diff options
| -rw-r--r-- | src/conditional/if.h | 21 | ||||
| -rw-r--r-- | test.cc | 6 | 
2 files changed, 27 insertions, 0 deletions
diff --git a/src/conditional/if.h b/src/conditional/if.h new file mode 100644 index 0000000..29aa6f0 --- /dev/null +++ b/src/conditional/if.h @@ -0,0 +1,21 @@ +#ifndef TYPEASVALUE_SRC_CONDITIONAL_IF_H_ +#define TYPEASVALUE_SRC_CONDITIONAL_IF_H_ + +#include <type_traits> + +namespace tav { + +template < +	bool     Condition, +	typename IfBranch, +	typename ElseBranch +> +using If = typename std::conditional< +	Condition, +	IfBranch, +	ElseBranch +>::type; + +} + +#endif  // TYPEASVALUE_SRC_CONDITIONAL_IF_H_ @@ -2,6 +2,7 @@  #include "type.h"  #include "operation/math.h" +#include "conditional/if.h"  class TypeAsValueTest : public ::testing::Test { }; @@ -16,6 +17,11 @@ TEST_F(TypeAsValueTest, BasicMath) {  	EXPECT_EQ(5,  ( tav::divide<tav::Int<10>, tav::Int<2>>::value ));  } +TEST_F(TypeAsValueTest, Conditional) { +	EXPECT_EQ(1, ( tav::If<true,  tav::Int<1>, tav::Int<2>>::value )); +	EXPECT_EQ(2, ( tav::If<false, tav::Int<1>, tav::Int<2>>::value )); +} +  int main(int argc, char **argv) {  	testing::InitGoogleTest(&argc, argv);  | 
