]> git.lyx.org Git - lyx.git/blob - boost/boost/utility.hpp
82a7d13219fcc8aaba987b203c62b3c5db2b9ec4
[lyx.git] / boost / boost / utility.hpp
1 //  boost utility.hpp header file  -------------------------------------------//
2
3 //  (C) Copyright boost.org 1999. Permission to copy, use, modify, sell
4 //  and distribute this software is granted provided this copyright
5 //  notice appears in all copies. This software is provided "as is" without
6 //  express or implied warranty, and with no claim as to its suitability for
7 //  any purpose.
8
9 //  See http://www.boost.org for most recent version including documentation.
10
11 //  Classes appear in alphabetical order
12
13 //  Revision History
14 //  26 Jan 00  protected noncopyable destructor added (Miki Jovanovic)
15 //  10 Dec 99  next() and prior() templates added (Dave Abrahams)
16 //  30 Aug 99  moved cast templates to cast.hpp (Beman Dawes)
17 //   3 Aug 99  cast templates added
18 //  20 Jul 99  name changed to utility.hpp 
19 //   9 Jun 99  protected noncopyable default ctor
20 //   2 Jun 99  Initial Version. Class noncopyable only contents (Dave Abrahams)
21
22 #ifndef BOOST_UTILITY_HPP
23 #define BOOST_UTILITY_HPP
24
25 #include <boost/config.hpp>
26 #include <cstddef>            // for size_t
27 #include <utility>            // for std::pair
28
29 namespace boost
30 {
31
32 //  next() and prior() template functions  -----------------------------------//
33
34     //  Helper functions for classes like bidirectional iterators not supporting
35     //  operator+ and operator-.
36     //
37     //  Usage:
38     //    const std::list<T>::iterator p = get_some_iterator();
39     //    const std::list<T>::iterator prev = boost::prior(p);
40
41     //  Contributed by Dave Abrahams
42
43     template <class T>
44     T next(T x) { return ++x; }
45
46     template <class T>
47     T prior(T x) { return --x; }
48
49
50 //  class noncopyable  -------------------------------------------------------//
51
52     //  Private copy constructor and copy assignment ensure classes derived from
53     //  class noncopyable cannot be copied.
54
55     //  Contributed by Dave Abrahams
56
57     class noncopyable
58     {
59     protected:
60         noncopyable(){}
61         ~noncopyable(){}
62     private:  // emphasize the following members are private
63         noncopyable( const noncopyable& );
64         const noncopyable& operator=( const noncopyable& );
65     }; // noncopyable
66
67 //  class tied  -------------------------------------------------------//
68
69     // A helper for conveniently assigning the two values from a pair
70     // into separate variables. The idea for this comes from Jaakko J\84rvi's
71     // Binder/Lambda Library.
72
73     // Constributed by Jeremy Siek
74
75     template <class A, class B>
76     class tied {
77     public:
78       inline tied(A& a, B& b) : _a(a), _b(b) { }
79       template <class U, class V>
80       inline tied& operator=(const std::pair<U,V>& p) {
81         _a = p.first;
82         _b = p.second;
83         return *this;
84       }
85     protected:
86       A& _a;
87       B& _b;
88     };
89
90     template <class A, class B>
91     inline tied<A,B> tie(A& a, B& b) { return tied<A,B>(a, b); }
92
93 } // namespace boost
94
95 #endif  // BOOST_UTILITY_HPP
96