diff --git a/doc/copy_cv_ref.qbk b/doc/copy_cv_ref.qbk new file mode 100644 index 0000000..95256ff --- /dev/null +++ b/doc/copy_cv_ref.qbk @@ -0,0 +1,65 @@ +[/ +Copyright 2019 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:copy_cv_ref copy_cv_ref] + + template + struct copy_cv_ref + { + typedef __below type; + }; + + template + using copy_cv_ref_t = typename copy_cv_ref::type; + +__type [^T /cvref/], where /cvref/ are the cvref-qualifiers of `U`. + +__header `#include ` or +`#include >` + +[table Examples + +[[Expression] [Result Type]] + +[[`copy_cv_ref::type`][`const int`]] + +[[`copy_cv_ref::type`][`volatile int`]] + +[[`copy_cv_ref::type`][`const volatile int`]] + +[[`copy_cv_ref::type`][`int&`]] + +[[`copy_cv_ref::type`][`const int&`]] + +[[`copy_cv_ref::type`][`volatile int&`]] + +[[`copy_cv_ref::type`][`const volatile int&`]] + +[[`copy_cv_ref::type`][`int&&`]] + +[[`copy_cv_ref::type`][`const int&&`]] + +[[`copy_cv_ref::type`][`volatile int&&`]] + +[[`copy_cv_ref::type`][`const volatile int&&`]] + +[[`copy_cv_ref::type`][`int&`]] + +[[`copy_cv_ref::type`][`int&`]] + +[[`copy_cv_ref::type`][`int&`]] + +[[`copy_cv_ref::type`][`int&`]] + +] + +[all_compilers] The type alias `copy_cv_ref_t` is only available if the compiler +supports template aliases. + +[endsect] diff --git a/doc/copy_reference.qbk b/doc/copy_reference.qbk new file mode 100644 index 0000000..9a97e03 --- /dev/null +++ b/doc/copy_reference.qbk @@ -0,0 +1,53 @@ +[/ +Copyright 2019 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:copy_reference copy_reference_] + + template + struct copy_reference + { + typedef __below type; + }; + + template + using copy_reference_t = typename copy_reference::type; + +__type [^T /ref/], where /ref/ are the ref-qualifiers of `U`. + +__header `#include ` or +`#include >` + +[table Examples + +[[Expression] [Result Type]] + +[[`copy_reference::type`][`int`]] + +[[`copy_reference::type`] [`int&`]] + +[[`copy_reference::type`] [`int&&`]] + +[[`copy_reference::type`] [`int&`]] + +[[`copy_reference::type`] [`int&`]] + +[[`copy_reference::type`] [`int&`]] + +[[`copy_reference::type`] [`int&&`]] + +[[`copy_reference::type`] [`int&`]] + +[[`copy_reference::type`] [`int&&`]] + +] + +[all_compilers] The type alias `copy_reference_t` is only available if the compiler +supports template aliases. + +[endsect] diff --git a/doc/history.qbk b/doc/history.qbk index 54c3d09..6d0def8 100644 --- a/doc/history.qbk +++ b/doc/history.qbk @@ -9,7 +9,7 @@ [h4 Boost-1.70.0] -* Added new traits __is_bounded_array, __is_unbounded_array. +* Added new traits __is_bounded_array, __is_unbounded_array, __copy_reference, __copy_cv_ref. [h4 Boost-1.68.0] diff --git a/doc/type_traits.qbk b/doc/type_traits.qbk index 8d3aaed..ce3f1d4 100644 --- a/doc/type_traits.qbk +++ b/doc/type_traits.qbk @@ -146,6 +146,8 @@ [def __is_complex [link boost_typetraits.reference.is_complex is_complex]] [def __copy_cv [link boost_typetraits.reference.copy_cv copy_cv]] +[def __copy_cv_ref [link boost_typetraits.reference.copy_cv_ref copy_cv_ref]] +[def __copy_reference [link boost_typetraits.reference.copy_reference copy_reference]] [def __type_identity [link boost_typetraits.reference.type_identity type_identity]] [def __declval [link boost_typetraits.reference.declval declval]] @@ -307,6 +309,8 @@ that is the result of the transformation. [include conditional.qbk] [include common_type.qbk] [include copy_cv.qbk] +[include copy_cv_ref.qbk] +[include copy_reference.qbk] [include decay.qbk] [include declval.qbk] [include detected.qbk] diff --git a/include/boost/type_traits.hpp b/include/boost/type_traits.hpp index a767e41..d61d5d7 100644 --- a/include/boost/type_traits.hpp +++ b/include/boost/type_traits.hpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/include/boost/type_traits/copy_cv_ref.hpp b/include/boost/type_traits/copy_cv_ref.hpp new file mode 100644 index 0000000..59cbc66 --- /dev/null +++ b/include/boost/type_traits/copy_cv_ref.hpp @@ -0,0 +1,31 @@ +/* +Copyright 2019 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_COPY_CV_REF_HPP_INCLUDED +#define BOOST_TT_COPY_CV_REF_HPP_INCLUDED + +#include +#include +#include + +namespace boost { + +template +struct copy_cv_ref { + typedef typename copy_reference::type >::type, U>::type type; +}; + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template +using copy_cv_ref_t = typename copy_cv_ref::type; +#endif + +} /* boost */ + +#endif diff --git a/include/boost/type_traits/copy_reference.hpp b/include/boost/type_traits/copy_reference.hpp new file mode 100644 index 0000000..0056681 --- /dev/null +++ b/include/boost/type_traits/copy_reference.hpp @@ -0,0 +1,35 @@ +/* +Copyright 2019 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_COPY_REFERENCE_HPP_INCLUDED +#define BOOST_TT_COPY_REFERENCE_HPP_INCLUDED + +#include +#include +#include +#include +#include + +namespace boost { + +template +struct copy_reference { + typedef typename conditional::value, + typename add_rvalue_reference::type, + typename conditional::value, + typename add_lvalue_reference::type, T>::type>::type type; +}; + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template +using copy_reference_t = typename copy_reference::type; +#endif + +} /* boost */ + +#endif diff --git a/test/copy_cv_ref_test.cpp b/test/copy_cv_ref_test.cpp new file mode 100644 index 0000000..974b6fd --- /dev/null +++ b/test/copy_cv_ref_test.cpp @@ -0,0 +1,186 @@ +/* +Copyright 2019 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 +#else +#include +#endif +#include "test.hpp" +#include "check_type.hpp" + +TT_TEST_BEGIN(copy_cv_ref) + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, int&&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const int&&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, volatile int&&); + +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +BOOST_CHECK_TYPE3(::tt::copy_cv_ref::type, const volatile int&&); +#endif + +TT_TEST_END diff --git a/test/copy_reference_test.cpp b/test/copy_reference_test.cpp new file mode 100644 index 0000000..e304288 --- /dev/null +++ b/test/copy_reference_test.cpp @@ -0,0 +1,33 @@ +/* +Copyright 2019 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 +#else +#include +#endif +#include "test.hpp" +#include "check_type.hpp" + +TT_TEST_BEGIN(copy_reference) + +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int); +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&); + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&&); +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&); +BOOST_CHECK_TYPE3(::tt::copy_reference::type, int&&); +#endif + +TT_TEST_END