enable_if.cpp
Go to the documentation of this file.
1 
9 /*****************************************************************************
10 ** Includes
11 *****************************************************************************/
12 
13 #include <gtest/gtest.h>
14 #include "../../include/ecl/mpl/enable_if.hpp"
15 #include "../../include/ecl/mpl/bool.hpp"
16 
20 /*****************************************************************************
21 ** Using
22 *****************************************************************************/
23 
24 using ecl::enable_if;
25 
26 /*****************************************************************************
27 ** Classes
28 *****************************************************************************/
29 
30 namespace ecl {
31 namespace mpl {
32 namespace tests {
33 
34 /*****************************************************************************
35 ** Is Float
36 *****************************************************************************/
37 
38 template <typename T>
39 class is_float : public ecl::False {};
40 
41 template <>
42 class is_float<float> : public ecl::True {};
43 
44 template <>
45 class is_float<double> : public ecl::True {};
46 
50 template <typename T, typename Enable = void>
51 class TestDude {
52 public:
53  bool isSpecialisation() { return false; }
54 };
58 template <typename T>
59 class TestDude< T, typename enable_if< is_float<T> >::type > {
60 public:
61  bool isSpecialisation() { return true; }
62 };
63 
64 } // namespace tests
65 } // namespace mpl
66 } // namespace ecl
67 
68 /*****************************************************************************
69 ** Using
70 *****************************************************************************/
71 
72 using namespace ecl::mpl::tests;
73 
74 /*****************************************************************************
75 ** Tests
76 *****************************************************************************/
77 
78 TEST(EnableIfTests,oneshot) {
79  TestDude<float> float_dude;
80  TestDude<int> int_dude;
81  bool result;
82  result = float_dude.isSpecialisation();
83  EXPECT_EQ(true, result);
84  result = int_dude.isSpecialisation();
85  EXPECT_EQ(false, result);
86 }
87 
88 /*****************************************************************************
89 ** Main program
90 *****************************************************************************/
91 
92 int main(int argc, char **argv) {
93 
94  testing::InitGoogleTest(&argc,argv);
95  return RUN_ALL_TESTS();
96 }
Embedded control libraries.
Enables the SFINAE concept.
Definition: enable_if.hpp:67
Integral constant wrapper for boolean values.
Definition: bool.hpp:32


ecl_mpl
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:18:28