mirror of
https://github.com/boostorg/type_traits.git
synced 2025-07-29 20:17:21 +02:00
Implement is_scoped_enum and is_unscoped_enum
This commit is contained in:
45
doc/is_scoped_enum.qbk
Normal file
45
doc/is_scoped_enum.qbk
Normal file
@ -0,0 +1,45 @@
|
||||
[/
|
||||
Copyright 2020 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:is_scoped_enum is_scoped_enum]
|
||||
|
||||
template<class T>
|
||||
struct is_scoped_enum
|
||||
: __tof { };
|
||||
|
||||
__inherit If T is a (possibly cv-qualified) scoped enumeration type
|
||||
(`enum class` but not `enum`), then inherits from __true_type, otherwise
|
||||
inherits from __false_type.
|
||||
|
||||
__header `#include <boost/type_traits/is_scoped_enum.hpp>`
|
||||
|
||||
[all_compilers]
|
||||
|
||||
__examples
|
||||
|
||||
[:Given: `enum class color { red, blue };` and `enum fruit { apple, orange };`]
|
||||
|
||||
[:`is_scoped_enum<color>` inherits from `__true_type`.]
|
||||
|
||||
[:`is_scoped_enum<fruit>` inherits from `__false_type`.]
|
||||
|
||||
[:`is_scoped_enum<color const>::type` is the type `__true_type`.]
|
||||
|
||||
[:`is_scoped_enum<color>::value` is an integral constant expression that
|
||||
evaluates to /true/.]
|
||||
|
||||
[:`is_scoped_enum<color&>::value` is an integral constant expression that
|
||||
evaluates to /false/.]
|
||||
|
||||
[:`is_scoped_enum<color*>::value` is an integral constant expression that
|
||||
evaluates to /false/.]
|
||||
|
||||
[:`is_scoped_enum<T>::value_type` is the type `bool`.]
|
||||
|
||||
[endsect]
|
45
doc/is_unscoped_enum.qbk
Normal file
45
doc/is_unscoped_enum.qbk
Normal file
@ -0,0 +1,45 @@
|
||||
[/
|
||||
Copyright 2020 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt).
|
||||
]
|
||||
|
||||
[section:is_unscoped_enum is_unscoped_enum]
|
||||
|
||||
template<class T>
|
||||
struct is_unscoped_enum
|
||||
: __tof { };
|
||||
|
||||
__inherit If T is a (possibly cv-qualified) unscoped enumeration type
|
||||
(`enum` but not `enum class`), then inherits from __true_type, otherwise
|
||||
inherits from __false_type.
|
||||
|
||||
__header `#include <boost/type_traits/is_unscoped_enum.hpp>`
|
||||
|
||||
[all_compilers]
|
||||
|
||||
__examples
|
||||
|
||||
[:Given: `enum color { red, blue };` and `enum class fruit { apple, orange };`]
|
||||
|
||||
[:`is_unscoped_enum<color>` inherits from `__true_type`.]
|
||||
|
||||
[:`is_unscoped_enum<fruit>` inherits from `__false_type`.]
|
||||
|
||||
[:`is_unscoped_enum<color const>::type` is the type `__true_type`.]
|
||||
|
||||
[:`is_unscoped_enum<color>::value` is an integral constant expression that
|
||||
evaluates to /true/.]
|
||||
|
||||
[:`is_unscoped_enum<color&>::value` is an integral constant expression that
|
||||
evaluates to /false/.]
|
||||
|
||||
[:`is_unscoped_enum<color*>::value` is an integral constant expression that
|
||||
evaluates to /false/.]
|
||||
|
||||
[:`is_unscoped_enum<T>::value_type` is the type `bool`.]
|
||||
|
||||
[endsect]
|
@ -55,6 +55,8 @@
|
||||
[def __is_unbounded_array [link boost_typetraits.reference.is_unbounded_array is_unbounded_array]]
|
||||
[def __is_union [link boost_typetraits.reference.is_union is_union]]
|
||||
[def __is_class [link boost_typetraits.reference.is_class is_class]]
|
||||
[def __is_scoped_enum [link boost_typetraits.reference.is_scoped_enum is_scoped_enum]]
|
||||
[def __is_unscoped_enum [link boost_typetraits.reference.is_unscoped_enum is_unscoped_enum]]
|
||||
[def __is_enum [link boost_typetraits.reference.is_enum is_enum]]
|
||||
[def __is_enum [link boost_typetraits.reference.is_enum is_enum]]
|
||||
[def __is_function [link boost_typetraits.reference.is_function is_function]]
|
||||
@ -434,10 +436,12 @@ See __has_trivial_constructor.
|
||||
[include is_rvalue_reference.qbk]
|
||||
[include is_same.qbk]
|
||||
[include is_scalar.qbk]
|
||||
[include is_scoped_enum.qbk]
|
||||
[include is_signed.qbk]
|
||||
[include is_stateless.qbk]
|
||||
[include is_unbounded_array.qbk]
|
||||
[include is_union.qbk]
|
||||
[include is_unscoped_enum.qbk]
|
||||
[include is_unsigned.qbk]
|
||||
[include is_virtual_base_of.qbk]
|
||||
[include is_void.qbk]
|
||||
|
@ -128,9 +128,11 @@
|
||||
#include <boost/type_traits/is_rvalue_reference.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_scalar.hpp>
|
||||
#include <boost/type_traits/is_scoped_enum.hpp>
|
||||
#include <boost/type_traits/is_signed.hpp>
|
||||
#include <boost/type_traits/is_stateless.hpp>
|
||||
#include <boost/type_traits/is_union.hpp>
|
||||
#include <boost/type_traits/is_unscoped_enum.hpp>
|
||||
#include <boost/type_traits/is_unsigned.hpp>
|
||||
#include <boost/type_traits/is_virtual_base_of.hpp>
|
||||
#include <boost/type_traits/is_void.hpp>
|
||||
|
26
include/boost/type_traits/is_scoped_enum.hpp
Normal file
26
include/boost/type_traits/is_scoped_enum.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
Copyright 2020 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#ifndef BOOST_TT_IS_SCOPED_ENUM_HPP_INCLUDED
|
||||
#define BOOST_TT_IS_SCOPED_ENUM_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/conjunction.hpp>
|
||||
#include <boost/type_traits/is_enum.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/type_traits/negation.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
struct is_scoped_enum
|
||||
: conjunction<is_enum<T>, negation<is_convertible<T, int> > >::type { };
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
25
include/boost/type_traits/is_unscoped_enum.hpp
Normal file
25
include/boost/type_traits/is_unscoped_enum.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright 2020 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
#ifndef BOOST_TT_IS_UNSCOPED_ENUM_HPP_INCLUDED
|
||||
#define BOOST_TT_IS_UNSCOPED_ENUM_HPP_INCLUDED
|
||||
|
||||
#include <boost/type_traits/conjunction.hpp>
|
||||
#include <boost/type_traits/is_enum.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
template<class T>
|
||||
struct is_unscoped_enum
|
||||
: conjunction<is_enum<T>, is_convertible<T, int> >::type { };
|
||||
|
||||
} /* boost */
|
||||
|
||||
#endif
|
36
test/is_scoped_enum_test.cpp
Normal file
36
test/is_scoped_enum_test.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2020 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifdef TEST_STD
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <boost/type_traits/is_scoped_enum.hpp>
|
||||
#endif
|
||||
#include "check_integral_constant.hpp"
|
||||
|
||||
enum Unscoped {
|
||||
Constant = 1
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
|
||||
enum class Scoped {
|
||||
Constant = 2
|
||||
};
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(is_scoped_enum)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_scoped_enum<void>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_scoped_enum<int>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_scoped_enum<Unscoped>::value, false);
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_scoped_enum<Scoped>::value, true);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
36
test/is_unscoped_enum_test.cpp
Normal file
36
test/is_unscoped_enum_test.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright 2020 Glen Joseph Fernandes
|
||||
(glenjofe@gmail.com)
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifdef TEST_STD
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <boost/type_traits/is_unscoped_enum.hpp>
|
||||
#endif
|
||||
#include "check_integral_constant.hpp"
|
||||
|
||||
enum Unscoped {
|
||||
Constant = 1
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
|
||||
enum class Scoped {
|
||||
Constant = 2
|
||||
};
|
||||
#endif
|
||||
|
||||
TT_TEST_BEGIN(is_unscoped_enum)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unscoped_enum<void>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unscoped_enum<int>::value, false);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unscoped_enum<Unscoped>::value, true);
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS)
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unscoped_enum<Scoped>::value, false);
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
Reference in New Issue
Block a user