-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding remove_cvref and type_identity
- Loading branch information
Showing
6 changed files
with
101 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "tools/overload.hpp" | ||
#include "tools/concepts.hpp" | ||
|
||
#include "tools/Log.hpp" | ||
|
||
#include "tools/std20/type_traits.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef NJOY_TOOLS_STD20_TYPE_TRAITS | ||
#define NJOY_TOOLS_STD20_TYPE_TRAITS | ||
|
||
// system includes | ||
#include <type_traits> | ||
|
||
// other includes | ||
|
||
namespace njoy { | ||
namespace tools { | ||
namespace std20 { | ||
|
||
template < typename T > | ||
struct remove_cvref { | ||
using type = std::remove_cv_t< std::remove_reference_t< T > >; | ||
}; | ||
|
||
template < typename T > | ||
using remove_cvref_t = typename remove_cvref< T >::type; | ||
|
||
template < typename T > | ||
struct type_identity { | ||
using type = T; | ||
}; | ||
|
||
template < typename T > | ||
using type_identity_t = typename type_identity< T >::type; | ||
|
||
} // std20 namespace | ||
} // tools namespace | ||
} // njoy namespace | ||
|
||
#endif |
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,2 @@ | ||
add_cpp_test( std20.type_traits.remove_cvref remove_cvref.test.cpp ) | ||
add_cpp_test( std20.type_traits.type_identity type_identity.test.cpp ) |
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,31 @@ | ||
// include Catch2 | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
// what we are testing | ||
#include "tools/std20/type_traits.hpp" | ||
|
||
// other includes | ||
|
||
// convenience typedefs | ||
using namespace njoy::tools; | ||
|
||
SCENARIO( "remove_cvref and remove_cvref_t" ) { | ||
|
||
CHECK( std::is_same_v< std20::remove_cvref< int >::type, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref< int& >::type, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref< int&& >::type, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref< const int& >::type, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref< int[2] >::type, int[2] > ); | ||
CHECK( std::is_same_v< std20::remove_cvref< const int[2] >::type, int[2] > ); | ||
CHECK( std::is_same_v< std20::remove_cvref< const int(&)[2] >::type, int[2] > ); | ||
CHECK( std::is_same_v< std20::remove_cvref< int(int) >::type, int(int) > ); | ||
|
||
CHECK( std::is_same_v< std20::remove_cvref_t< int >, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref_t< int& >, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref_t< int&& >, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref_t< const int& >, int > ); | ||
CHECK( std::is_same_v< std20::remove_cvref_t< int[2] >, int[2] > ); | ||
CHECK( std::is_same_v< std20::remove_cvref_t< const int[2] >, int[2] > ); | ||
CHECK( std::is_same_v< std20::remove_cvref_t< const int(&)[2] >, int[2] > ); | ||
CHECK( std::is_same_v< std20::remove_cvref_t< int(int) >, int(int) > ); | ||
} // SCENARIO |
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,31 @@ | ||
// include Catch2 | ||
#include <catch2/catch_test_macros.hpp> | ||
|
||
// what we are testing | ||
#include "tools/std20/type_traits.hpp" | ||
|
||
// other includes | ||
|
||
// convenience typedefs | ||
using namespace njoy::tools; | ||
|
||
SCENARIO( "type_identity and type_identity_t" ) { | ||
|
||
CHECK( std::is_same_v< std20::type_identity< int >::type, int > ); | ||
CHECK( std::is_same_v< std20::type_identity< int& >::type, int& > ); | ||
CHECK( std::is_same_v< std20::type_identity< int&& >::type, int&& > ); | ||
CHECK( std::is_same_v< std20::type_identity< const int& >::type, const int& > ); | ||
CHECK( std::is_same_v< std20::type_identity< int[2] >::type, int[2] > ); | ||
CHECK( std::is_same_v< std20::type_identity< const int[2] >::type, const int[2] > ); | ||
CHECK( std::is_same_v< std20::type_identity< const int(&)[2] >::type, const int(&)[2] > ); | ||
CHECK( std::is_same_v< std20::type_identity< int(int) >::type, int(int) > ); | ||
|
||
CHECK( std::is_same_v< std20::type_identity_t< int >, int > ); | ||
CHECK( std::is_same_v< std20::type_identity_t< int& >, int& > ); | ||
CHECK( std::is_same_v< std20::type_identity_t< int&& >, int&& > ); | ||
CHECK( std::is_same_v< std20::type_identity_t< const int& >, const int& > ); | ||
CHECK( std::is_same_v< std20::type_identity_t< int[2] >, int[2] > ); | ||
CHECK( std::is_same_v< std20::type_identity_t< const int[2] >, const int[2] > ); | ||
CHECK( std::is_same_v< std20::type_identity_t< const int(&)[2] >, const int(&)[2] > ); | ||
CHECK( std::is_same_v< std20::type_identity_t< int(int) >, int(int) > ); | ||
} // SCENARIO |