Last active
April 15, 2021 22:35
-
-
Save Au-lit/c1dfd06a95542ca3dc63bc4d085bf3de to your computer and use it in GitHub Desktop.
A C++ is_char type trait.
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
// © Copyright 2021 Ollivier Roberge | |
#ifndef IS_CHAR_IMPL | |
#define IS_CHAR_IMPL | |
#include <type_traits> | |
template<typename T> struct is_char : std::false_type {}; | |
template<> struct is_char<char> : std::true_type {}; | |
template<> struct is_char<wchar_t> : std::true_type {}; | |
template<> struct is_char<char16_t> : std::true_type {}; | |
template<> struct is_char<char32_t> : std::true_type {}; | |
#if __cpp_char8_t >= 201811L | |
template<> struct is_char<char8_t> : std::true_type {}; | |
#endif | |
#if __cpp_inline_variables >= 201606L | |
template<typename T> inline constexpr bool is_char_v = is_char<T>::value; | |
#endif | |
#if __cpp_concepts >= 201907L | |
template<typename T> concept character = is_char<T>::value; | |
#endif | |
#endif // !defined(IS_CHAR_IMPL) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment