-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef ZLL_META_INTEGRALCONSTANT_HPP | ||
#define ZLL_META_INTEGRALCONSTANT_HPP | ||
|
||
namespace zll { | ||
namespace meta { | ||
|
||
template <typename T, T VALUE_V> | ||
struct integral_constant { | ||
typedef T value_type; | ||
typedef integral_constant<T, VALUE_V> type; | ||
|
||
static const value_type value = VALUE_V; | ||
|
||
operator value_type() const { return VALUE_V; } | ||
value_type operator()() const { return VALUE_V; } | ||
}; | ||
|
||
template <bool BOOL_V> | ||
struct bool_constant : integral_constant<bool, BOOL_V> {}; | ||
|
||
typedef bool_constant<true> true_type; | ||
typedef bool_constant<false> false_type; | ||
|
||
} // namespace meta | ||
} // namespace zll | ||
|
||
#endif // ZLL_META_INTEGRALCONSTANT_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "zll/meta/integral_constant.hpp" | ||
#include "zll/debug/static_assert.hpp" | ||
|
||
#include <utest.h> | ||
|
||
UTEST(meta_integral_constant, int_constant) { | ||
typedef zll::meta::integral_constant<int, 2> two_t; | ||
|
||
const two_t two = two_t(); | ||
ASSERT_EQ(two_t::value, 2); | ||
ASSERT_EQ(two(), 2); | ||
const int val = two; | ||
|
||
ASSERT_EQ(val, 2); | ||
ZLL_STATIC_ASSERT((two_t::value == 2)); | ||
} | ||
|
||
UTEST(meta_integral_constant, bool_constant) { | ||
{ | ||
const zll::meta::true_type true_v; | ||
ASSERT_TRUE((zll::meta::true_type::value)); | ||
ASSERT_TRUE(true_v); | ||
ASSERT_TRUE(true_v()); | ||
ZLL_STATIC_ASSERT((zll::meta::true_type::value)); | ||
} | ||
{ | ||
const zll::meta::false_type false_v; | ||
ASSERT_FALSE((zll::meta::false_type::value)); | ||
ASSERT_FALSE(false_v); | ||
ASSERT_FALSE(false_v()); | ||
ZLL_STATIC_ASSERT(!(zll::meta::false_type::value)); | ||
} | ||
} |