Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(const_generics)]
- trait Helper {
- type T;
- }
- struct ITE<True, False, const B: bool> (
- ::core::marker::PhantomData<(True, False)>,
- );
- impl<True, False> Helper
- for ITE<True, False, {true}>
- {
- type T = True;
- }
- impl<True, False> Helper
- for ITE<True, False, {false}>
- {
- type T = False;
- }
- struct Foo {
- // x: String,
- }
- macro_rules! type_level_conditional {(
- type $T:ident =
- if { $cond:expr } {
- $True:ty
- } else {
- $False:ty
- }
- ;
- ) => (
- type $T = <$crate::ITE<$True, $False, {
- ::core::mem::size_of::<Foo>() == 0
- }> as $crate::Helper>::T;
- )}
- type_level_conditional! {
- type T = if { ::core::mem::size_of::<Foo>() == 0 } {
- i32
- } else {
- f32
- };
- }
- fn is_i32 (_: &i32) {}
- fn is_f32 (_: &f32) {}
- fn check (x: T)
- {
- is_i32(&x);
- is_f32(&x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement