Skip to content

Commit

Permalink
✨ add remove_cv traits
Browse files Browse the repository at this point in the history
  • Loading branch information
zie87 committed Oct 6, 2023
1 parent 9ba7a90 commit 3117fc7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions include/zll/meta/remove_cv.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef ZLL_META_REMOVECV_HPP
#define ZLL_META_REMOVECV_HPP

namespace zll {
namespace meta {

// clang-format off
template <typename T> struct remove_const { typedef T type; };
template <typename T> struct remove_const<const T> { typedef T type; };
// clang-format on

// clang-format off
template <typename T> struct remove_volatile { typedef T type; };
template <typename T> struct remove_volatile<volatile T> { typedef T type; };
// clang-format on

// clang-format off
template<typename T> struct remove_cv { typedef T type; };
template<typename T> struct remove_cv<const T> { typedef T type; };
template<typename T> struct remove_cv<volatile T> { typedef T type; };
template<typename T> struct remove_cv<const volatile T> { typedef T type; };
// clang-format on

} // namespace meta
} // namespace zll

#endif // ZLL_META_ISSAME_HPP
3 changes: 3 additions & 0 deletions include/zll/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@

#include "zll/meta/is_same.hpp"

#include "zll/meta/remove_cv.hpp"


#endif // ZLL_TYPETRAITS_HPP
1 change: 1 addition & 0 deletions tests/unit_tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
unit_tests_srcs = [
'meta/integral_constant_tests.cpp',
'meta/is_same_tests.cpp',
'meta/remove_cv_tests.cpp',
'main.cpp',
]

Expand Down
28 changes: 28 additions & 0 deletions tests/unit_tests/meta/remove_cv_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "zll/meta/remove_cv.hpp"
#include "zll/meta/is_same.hpp"

#include <utest.h>

struct test_dummy {};
struct test_child : test_dummy {};

UTEST(meta_remove_cv, remove_const) {
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_const<int>::type, int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_const<const int>::type, int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_const<volatile int>::type, volatile int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_const<const volatile int>::type, volatile int>::value));
}

UTEST(meta_remove_cv, remove_volatile) {
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_volatile<int>::type, int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_volatile<const int>::type, const int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_volatile<volatile int>::type, int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_volatile<const volatile int>::type, const int>::value));
}

UTEST(meta_remove_cv, remove_cv) {
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_cv<int>::type, int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_cv<const int>::type, int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_cv<volatile int>::type, int>::value));
ASSERT_TRUE((zll::meta::is_same<zll::meta::remove_cv<const volatile int>::type, int>::value));
}

0 comments on commit 3117fc7

Please sign in to comment.