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