Implement is_bounded_array and is_unbounded_array

This commit is contained in:
Glen Fernandes
2018-11-07 18:10:38 -05:00
parent b8e0395cd8
commit d8bdd309d7
8 changed files with 229 additions and 0 deletions

View File

@ -7,6 +7,10 @@
[section:history History]
[h4 Boost-1.70.0]
* Added new traits __is_bounded_array, __is_unbounded_array.
[h4 Boost-1.68.0]
* Added support for detecting trivial moves on clang.

34
doc/is_bounded_array.qbk Normal file
View File

@ -0,0 +1,34 @@
[/
Copyright 2018 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_bounded_array is_bounded_array]
template<class T>
struct is_bounded_array
: __tof { };
__inherit If T is a (possibly cv-qualified) array type of known bound, then
inherits from __true_type, otherwise inherits from __false_type.
__header `#include <boost/type_traits/is_bounded_array.hpp>`
[all_compilers]
__examples
[:`is_bounded_array<int[2]>` inherits from `__true_type`.]
[:`is_bounded_array<char[2][3]>::type` is the type `__true_type`.]
[:`is_bounded_array<double[2]>::value` is an integral constant expression that
evaluates to /true/.]
[:`is_bounded_array<T>::value_type` is the type `bool`.]
[endsect]

View File

@ -0,0 +1,34 @@
[/
Copyright 2018 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_unbounded_array is_unbounded_array]
template<class T>
struct is_unbounded_array
: __tof { };
__inherit If T is a (possibly cv-qualified) array type of unknown bound, then
inherits from __true_type, otherwise inherits from __false_type.
__header `#include <boost/type_traits/is_unbounded_array.hpp>`
[all_compilers]
__examples
[:`is_unbounded_array<int[]>` inherits from `__true_type`.]
[:`is_unbounded_array<char[][3]>::type` is the type `__true_type`.]
[:`is_unbounded_array<double[]>::value` is an integral constant expression that
evaluates to /true/.]
[:`is_unbounded_array<T>::value_type` is the type `bool`.]
[endsect]

View File

@ -51,6 +51,8 @@
[def __is_rvalue_reference [link boost_typetraits.reference.is_rvalue_reference is_rvalue_reference]]
[def __is_member_pointer [link boost_typetraits.reference.is_member_pointer is_member_pointer]]
[def __is_array [link boost_typetraits.reference.is_array is_array]]
[def __is_bounded_array [link boost_typetraits.reference.is_bounded_array is_bounded_array]]
[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_enum [link boost_typetraits.reference.is_enum is_enum]]
@ -385,6 +387,7 @@ See __has_trivial_constructor.
[include is_array.qbk]
[include is_assignable.qbk]
[include is_base_of.qbk]
[include is_bounded_array.qbk]
[include is_class.qbk]
[include is_complete.qbk]
[include is_complex.qbk]
@ -424,6 +427,7 @@ See __has_trivial_constructor.
[include is_scalar.qbk]
[include is_signed.qbk]
[include is_stateless.qbk]
[include is_unbounded_array.qbk]
[include is_union.qbk]
[include is_unsigned.qbk]
[include is_virtual_base_of.qbk]

View File

@ -0,0 +1,42 @@
/*
Copyright 2018 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_BOUNDED_ARRAY_HPP_INCLUDED
#define BOOST_TT_IS_BOUNDED_ARRAY_HPP_INCLUDED
#include <boost/type_traits/integral_constant.hpp>
#include <cstddef>
namespace boost {
template<class T>
struct is_bounded_array
: false_type { };
#if !defined(BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS)
template<class T, std::size_t N>
struct is_bounded_array<T[N]>
: true_type { };
template<class T, std::size_t N>
struct is_bounded_array<const T[N]>
: true_type { };
template<class T, std::size_t N>
struct is_bounded_array<volatile T[N]>
: true_type { };
template<class T, std::size_t N>
struct is_bounded_array<const volatile T[N]>
: true_type { };
#endif
} /* boost */
#endif

View File

@ -0,0 +1,41 @@
/*
Copyright 2018 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_UNBOUNDED_ARRAY_HPP_INCLUDED
#define BOOST_TT_IS_UNBOUNDED_ARRAY_HPP_INCLUDED
#include <boost/type_traits/integral_constant.hpp>
namespace boost {
template<class T>
struct is_unbounded_array
: false_type { };
#if !defined(BOOST_NO_ARRAY_TYPE_SPECIALIZATIONS)
template<class T>
struct is_unbounded_array<T[]>
: true_type { };
template<class T>
struct is_unbounded_array<const T[]>
: true_type { };
template<class T>
struct is_unbounded_array<volatile T[]>
: true_type { };
template<class T>
struct is_unbounded_array<const volatile T[]>
: true_type { };
#endif
} /* boost */
#endif

View File

@ -0,0 +1,35 @@
/*
Copyright 2018 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_bounded_array.hpp>
#endif
#include "check_integral_constant.hpp"
TT_TEST_BEGIN(is_bounded_array)
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<void>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int*>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int&>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int[2]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<const int[3]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<const volatile int[4]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int[5][6]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int[]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<const int[]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<const volatile int[]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int[][7]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int(&)[8]>::value, false);
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_bounded_array<int(&&)[9]>::value, false);
#endif
TT_TEST_END

View File

@ -0,0 +1,35 @@
/*
Copyright 2018 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_unbounded_array.hpp>
#endif
#include "check_integral_constant.hpp"
TT_TEST_BEGIN(is_unbounded_array)
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<void>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int*>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int&>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int[2]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<const int[3]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<const volatile int[4]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int[5][6]>::value, false);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int[]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<const int[]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<const volatile int[]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int[][7]>::value, true);
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int(&)[8]>::value, false);
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_unbounded_array<int(&&)[9]>::value, false);
#endif
TT_TEST_END