Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add is_character #187

Open
gpeterhoff opened this issue Feb 4, 2024 · 1 comment
Open

add is_character #187

gpeterhoff opened this issue Feb 4, 2024 · 1 comment

Comments

@gpeterhoff
Copy link

gpeterhoff commented Feb 4, 2024

is_character.hpp

//	Distributed under the Boost Software License Version 1.0 https://www.boost.org/LICENSE_1_0.txt
//	Copyright Gero Peterhoff

#ifndef BOOST_TYPE_TRAITS_IS_CHARACTER_HPP
#define BOOST_TYPE_TRAITS_IS_CHARACTER_HPP

#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/remove_cvref.hpp>



namespace boost
{
template <typename Type> struct is_character				: public false_type{};
template <typename Type> struct is_character<volatile const Type>	: public is_character<Type>{};
template <typename Type> struct is_character<volatile Type>		: public is_character<Type>{};
template <typename Type> struct is_character<const Type>		: public is_character<Type>{};

#if defined(__cpp_unicode_characters)
template <> struct is_character<char32_t>	: public true_type{};
template <> struct is_character<char16_t>	: public true_type{};
#endif

#if defined(__cpp_char8_t)
template <> struct is_character<char8_t>	: public true_type{};
#endif

template <> struct is_character<wchar_t>	: public true_type{};
template <> struct is_character<char>		: public true_type{};



#if !defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template <typename Type> inline constexpr bool is_character_v = is_character<Type>::value;
#endif
}	//	boost

#endif	//	BOOST_TYPE_TRAITS_IS_CHARACTER_HPP
@pdimov
Copy link
Member

pdimov commented Feb 5, 2024

Character types are a standard concept, defined in https://eel.is/c++draft/basic.fundamental#11, and the above looks like the correct implementation for it.

This trait is occasionally useful to constrain functions taking C strings, e.g. https://github.com/boostorg/nowide/blob/e040930b0986d5a4b89d2b9b109a6233c2baa831/include/boost/nowide/detail/is_string_container.hpp#L26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants