1 // boost/identifier.hpp ----------------------------------------------------//
3 // Copyright Beman Dawes 2006
5 // Distributed under the Boost Software License, Version 1.0. (See accompanying
6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 // See documentation at http://www.boost.org/libs/utility
10 #ifndef BOOST_IDENTIFIER_HPP
11 #define BOOST_IDENTIFIER_HPP
13 #include <boost/utility/enable_if.hpp>
14 #include <boost/type_traits/is_base_of.hpp>
21 // class template identifier ---------------------------------------------//
23 // Always used as a base class so that different instantiations result in
24 // different class types even if instantiated with the same value type T.
26 // Expected usage is that T is often an integer type, best passed by
27 // value. There is no reason why T can't be a possibly larger class such as
28 // std::string, best passed by const reference.
30 // This implementation uses pass by value, based on expected common uses.
32 template <typename T
, typename D
>
38 const value_type
value() const { return m_value
; }
39 void assign( value_type v
) { m_value
= v
; }
41 bool operator==( const D
& rhs
) const { return m_value
== rhs
.m_value
; }
42 bool operator!=( const D
& rhs
) const { return m_value
!= rhs
.m_value
; }
43 bool operator< ( const D
& rhs
) const { return m_value
< rhs
.m_value
; }
44 bool operator<=( const D
& rhs
) const { return m_value
<= rhs
.m_value
; }
45 bool operator> ( const D
& rhs
) const { return m_value
> rhs
.m_value
; }
46 bool operator>=( const D
& rhs
) const { return m_value
>= rhs
.m_value
; }
48 typedef void (*unspecified_bool_type
)(D
); // without the D, unspecified_bool_type
49 static void unspecified_bool_true(D
){} // conversion allows relational operators
50 // between different identifier types
52 operator unspecified_bool_type() const { return m_value
== value_type() ? 0 : unspecified_bool_true
; }
53 bool operator!() const { return m_value
== value_type(); }
55 // constructors are protected so that class can only be used as a base class
58 explicit identifier( value_type v
) : m_value(v
) {}
60 #if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 // 1300 == VC++ 7.0 bug workaround
66 //#ifndef BOOST_NO_SFINAE
68 // template <class Ostream, class Id>
69 // typename enable_if< is_base_of< identifier< typename Id::value_type, Id >, Id >,
70 // Ostream & >::type operator<<( Ostream & os, const Id & id )
72 // return os << id.value();
75 // template <class Istream, class Id>
76 // typename enable_if< is_base_of< identifier< typename Id::value_type, Id >, Id >,
77 // Istream & >::type operator>>( Istream & is, Id & id )
79 // typename Id::value_type v;
89 #endif // BOOST_IDENTIFIER_HPP