diff --git a/include/utl/meta/integral.h b/include/utl/meta/integral.h index 4b15c65..e81f8a6 100644 --- a/include/utl/meta/integral.h +++ b/include/utl/meta/integral.h @@ -49,7 +49,7 @@ namespace meta { //! integral_constant //! An Integral Constant is a holder class for a compile-time value of an integral type. - //! Every Integral Constant is also a nullary Metafunction, returning itself. + //! Every Integral Constant is also a null-ary Metafunction, returning itself. //! An integral constant object is implicitly convertible to the corresponding //! run-time value of the wrapped integral type //! @{ @@ -85,6 +85,27 @@ namespace meta { using true_ = bool_; //!< The type used as a compile-time boolean with true value. using false_ = bool_; //!< The type used as a compile-time boolean with false value. + //! int8_ type: integral constant wrapper for \c int8_t + template + using int8_ = integral_c; + //! uint8_ type: integral constant wrapper for \c uint8_t + template + using uint8_ = integral_c; + + //! int16_ type: integral constant wrapper for \c int16_t + template + using int16_ = integral_c; + //! uint16_ type: integral constant wrapper for \c uint16_t + template + using uint16_ = integral_c; + + //! int32_ type: integral constant wrapper for \c int32_t + template + using int32_ = integral_c; + //! uint32_ type: integral constant wrapper for \c uint32_t + template + using uint32_ = integral_c; + //! char_ type: integral constant wrapper for \c char template using char_ = integral_c; diff --git a/include/utl/meta/operations.h b/include/utl/meta/operations.h index 595f3f7..296264e 100644 --- a/include/utl/meta/operations.h +++ b/include/utl/meta/operations.h @@ -108,7 +108,7 @@ namespace meta { //! @{ //! \return bitwise not (~) operation of its argument. - template using bitnot_ = integral_c; + template using bitnot_ = integral_c; //! \return bitwise and (&) operation of its arguments template using bitand_ = integral_c; @@ -121,10 +121,10 @@ namespace meta { using bitxor_ = integral_c; //! \return the result of bitwise shift left (<<) operation on _Tp. template - using shift_left = integral_c; + using shift_left = integral_c; //! \return the result of bitwise shift right (>>) operation on _Tp. template - using shift_right = integral_c> shift()), (_Tp() >> shift())>; + using shift_right = integral_c> shift())>; //! @} }} //!@} diff --git a/test/tests/Tmeta.cpp b/test/tests/Tmeta.cpp index 3be6621..bc67fd7 100644 --- a/test/tests/Tmeta.cpp +++ b/test/tests/Tmeta.cpp @@ -48,8 +48,26 @@ namespace test_meta { EXPECT_EQ(false, false_::value); EXPECT_EQ(true, (std::is_same::value)); EXPECT_EQ(true, true_::value); + + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42, int8_<42>::value); + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42u, uint8_<42u>::value); + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42, int16_<42>::value); + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42u, uint16_<42u>::value); + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42, int32_<42>::value); + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42u, uint32_<42u>::value); + + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42, char_<42>::value); EXPECT_EQ(true, (std::is_same::value_type>::value)); EXPECT_EQ(42, int_<42>::value); + EXPECT_EQ(true, (std::is_same::value_type>::value)); + EXPECT_EQ(42, long_<42>::value); EXPECT_EQ(true, (std::is_same::value_type>::value)); EXPECT_EQ(42U, index_t_<42U>::value); @@ -88,11 +106,15 @@ namespace test_meta { } TEST(Tmeta_logical, BitOperations) { - EXPECT_EQ (0x00, (bitand_, int_<0xAA>>())); - EXPECT_EQ (0xFF, (bitor_, int_<0xAA>>())); - EXPECT_EQ (0xFA, (bitxor_, int_<0xAF>>())); - EXPECT_EQ (0x00, (bitnot_>())); - //XXX: add shifts + EXPECT_EQ (0x00, (bitand_, uint8_<0xAA>>())); + EXPECT_EQ (0xFF, (bitor_ , uint8_<0xAA>>())); + EXPECT_EQ (0xFA, (bitxor_, uint8_<0xAF>>())); + EXPECT_EQ (0x00, (bitnot_>())); + + EXPECT_EQ (0x04, (shift_left, uint8_<2>>())); + EXPECT_EQ (0x00, (shift_left, uint8_<1>>())); + EXPECT_EQ (0x02, (shift_right, uint8_<2>>())); + EXPECT_EQ (0x00, (shift_right, uint8_<1>>())); } TEST(Tmeta_logical, TypeOperations) { @@ -103,10 +125,10 @@ namespace test_meta { EXPECT_EQ (true, (std::is_same, if_c, bool_>>())); EXPECT_EQ (true, (std::is_same, if_, int_<42>, bool_>>())); - EXPECT_EQ (true, (std::is_same, or_, bool_>>())); - EXPECT_EQ (true, (std::is_same, or_, bool_>>())); - EXPECT_EQ (true, (std::is_same, and_, bool_>>())); - EXPECT_EQ (true, (std::is_same, and_, bool_>>())); + EXPECT_EQ (true, (std::is_same>())); + EXPECT_EQ (true, (std::is_same>())); + EXPECT_EQ (true, (std::is_same>())); + EXPECT_EQ (true, (std::is_same>())); EXPECT_EQ (true, (same_())); EXPECT_EQ (false, (same_()));