forked from boostorg/type_traits
Added true_type and false_type to aid user-defined specialisations.
[SVN r21269]
This commit is contained in:
37
index.html
37
index.html
@ -16,7 +16,7 @@
|
||||
<a href="#transformations">Transformations Between Types</a>
|
||||
<a href="#synthesized">Synthesizing Types</a>
|
||||
<a href="#function_traits">Function Traits</a>
|
||||
<a href="#headers">Type traits headers</a>
|
||||
<a href="#headers">Type traits headers</a><BR><A href="#specializations">User defined specializations</A>
|
||||
<a href="#example">Example Code</a></pre>
|
||||
<h2><a name="intro"></a>Introduction</h2>
|
||||
<p>The contents of <boost/type_traits.hpp> are declared in namespace boost.</p>
|
||||
@ -850,7 +850,40 @@ bool const y = boost::is_convertible<D*,A*>::value; // error
|
||||
boost/type_traits/. So if for example some code requires
|
||||
is_class<>, then just include:</p>
|
||||
<pre><boost/type_traits/is_class.hpp></pre>
|
||||
<h2><a name="example"></a>Example code</h2>
|
||||
<h2><A name="specializations"></A>User defined specializations</h2>
|
||||
<P>Occationally the end user may need to provide their own specialization for one
|
||||
of the type traits - typically where intrinsic compiler support is required to
|
||||
implement a specific trait fully. These specializations should derive
|
||||
from boost::true_type or boost::false_type as appropriate:</P>
|
||||
<PRE># include <boost/type_traits/is_pod.hpp>
|
||||
# include <boost/type_traits/is_class.hpp>
|
||||
# include <boost/type_traits/is_union.hpp>
|
||||
|
||||
struct my_pod{};
|
||||
struct my_union
|
||||
{
|
||||
char c;
|
||||
int i;
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<>
|
||||
struct is_pod<my_pod>
|
||||
: public true_type{};
|
||||
template<>
|
||||
struct is_pod<my_union>
|
||||
: public true_type{};
|
||||
template<>
|
||||
struct is_union<my_union>
|
||||
: public true_type{};
|
||||
template<>
|
||||
struct is_class<my_union>
|
||||
: public false_type{};
|
||||
}
|
||||
|
||||
</PRE>
|
||||
<H2>Example code</H2>
|
||||
<p>Type-traits comes with four example programs that illustrate some of the ways
|
||||
in which the type traits templates may be used:</p>
|
||||
<h4>Copy_example.cpp</h4>
|
||||
|
@ -84,8 +84,10 @@ test-suite type_traits :
|
||||
[ type-traits-run tricky_is_enum_test.cpp ]
|
||||
[ type-traits-run tricky_partial_spec_test.cpp ]
|
||||
[ type-traits-run type_with_alignment_test.cpp ]
|
||||
[ type-traits-run udt_specialisations.cpp ]
|
||||
|
||||
; # type traits suite
|
||||
|
||||
|
||||
|
||||
|
||||
|
43
test/udt_specialisations.cpp
Normal file
43
test/udt_specialisations.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#include "test.hpp"
|
||||
#include "check_integral_constant.hpp"
|
||||
#ifdef TEST_STD
|
||||
# include <type_traits>
|
||||
#else
|
||||
# include <boost/type_traits/is_pod.hpp>
|
||||
# include <boost/type_traits/is_class.hpp>
|
||||
# include <boost/type_traits/is_union.hpp>
|
||||
#endif
|
||||
|
||||
struct my_pod{};
|
||||
struct my_union
|
||||
{
|
||||
char c;
|
||||
int i;
|
||||
};
|
||||
|
||||
namespace tt
|
||||
{
|
||||
template<>
|
||||
struct is_pod<my_pod>
|
||||
: public true_type{};
|
||||
template<>
|
||||
struct is_pod<my_union>
|
||||
: public true_type{};
|
||||
template<>
|
||||
struct is_union<my_union>
|
||||
: public true_type{};
|
||||
template<>
|
||||
struct is_class<my_union>
|
||||
: public false_type{};
|
||||
}
|
||||
|
||||
TT_TEST_BEGIN(is_pod)
|
||||
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pod<my_pod>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pod<my_union>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_union<my_union>::value, true);
|
||||
BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_class<my_union>::value, false);
|
||||
|
||||
TT_TEST_END
|
||||
|
Reference in New Issue
Block a user