1 | #ifndef BOOST_STRONG_TYPEDEF_HPP
|
---|
2 | #define BOOST_STRONG_TYPEDEF_HPP
|
---|
3 |
|
---|
4 | // MS compatible compilers support #pragma once
|
---|
5 | #if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
---|
6 | # pragma once
|
---|
7 | #endif
|
---|
8 |
|
---|
9 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
10 | // strong_typedef.hpp:
|
---|
11 |
|
---|
12 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
---|
13 | // Use, modification and distribution is subject to the Boost Software
|
---|
14 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
15 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
16 |
|
---|
17 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
18 |
|
---|
19 | // macro used to implement a strong typedef. strong typedef
|
---|
20 | // guarentees that two types are distinguised even though the
|
---|
21 | // share the same underlying implementation. typedef does not create
|
---|
22 | // a new type. BOOST_STRONG_TYPEDEF(T, D) creates a new type named D
|
---|
23 | // that operates as a type T.
|
---|
24 |
|
---|
25 | #include <boost/operators.hpp>
|
---|
26 |
|
---|
27 | #define BOOST_STRONG_TYPEDEF(T, D) \
|
---|
28 | struct D \
|
---|
29 | : boost::totally_ordered1< D \
|
---|
30 | , boost::totally_ordered2< D, T \
|
---|
31 | > > \
|
---|
32 | { \
|
---|
33 | T t; \
|
---|
34 | explicit D(const T t_) : t(t_) {}; \
|
---|
35 | D(){}; \
|
---|
36 | D(const D & t_) : t(t_.t){} \
|
---|
37 | D & operator=(const D & rhs) { t = rhs.t; return *this;} \
|
---|
38 | D & operator=(const T & rhs) { t = rhs; return *this;} \
|
---|
39 | operator const T & () const {return t; } \
|
---|
40 | operator T & () { return t; } \
|
---|
41 | bool operator==(const D & rhs) const { return t == rhs.t; } \
|
---|
42 | bool operator<(const D & rhs) const { return t < rhs.t; } \
|
---|
43 | };
|
---|
44 |
|
---|
45 | #endif // BOOST_STRONG_TYPEDEF_HPP
|
---|