• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Container static_vector
2 // Unit Test
3 
4 // Copyright (c) 2012-2013 Adam Wulkiewicz, Lodz, Poland.
5 // Copyright (c) 2012-2013 Andrew Hundt.
6 
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 #ifndef BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP
12 #define BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP
13 
14 #include <boost/container/static_vector.hpp>
15 
16 #define BOOST_SP_DISABLE_THREADS
17 #include <boost/shared_ptr.hpp>
18 #include "movable_int.hpp"
19 
20 using namespace boost::container;
21 
22 class value_ndc
23 {
24 public:
value_ndc(int a)25     explicit value_ndc(int a) : aa(a) {}
~value_ndc()26     ~value_ndc() {}
operator ==(value_ndc const & v) const27     bool operator==(value_ndc const& v) const { return aa == v.aa; }
operator <(value_ndc const & v) const28     bool operator<(value_ndc const& v) const { return aa < v.aa; }
29 private:
value_ndc(value_ndc const &)30     value_ndc(value_ndc const&) {}
operator =(value_ndc const &)31     value_ndc & operator=(value_ndc const&) { return *this; }
32     int aa;
33 };
34 
35 class value_nd
36 {
37 public:
value_nd(int a)38     explicit value_nd(int a) : aa(a) {}
~value_nd()39     ~value_nd() {}
operator ==(value_nd const & v) const40     bool operator==(value_nd const& v) const { return aa == v.aa; }
operator <(value_nd const & v) const41     bool operator<(value_nd const& v) const { return aa < v.aa; }
42 private:
43     int aa;
44 };
45 
46 class value_nc
47 {
48 public:
value_nc(int a=0)49     explicit value_nc(int a = 0) : aa(a) {}
~value_nc()50     ~value_nc() {}
operator ==(value_nc const & v) const51     bool operator==(value_nc const& v) const { return aa == v.aa; }
operator <(value_nc const & v) const52     bool operator<(value_nc const& v) const { return aa < v.aa; }
53 private:
value_nc(value_nc const &)54     value_nc(value_nc const&) {}
operator =(value_ndc const &)55     value_nc & operator=(value_ndc const&) { return *this; }
56     int aa;
57 };
58 
59 class counting_value
60 {
61     BOOST_COPYABLE_AND_MOVABLE(counting_value)
62 
63 public:
counting_value(int a=0,int b=0)64     explicit counting_value(int a = 0, int b = 0) : aa(a), bb(b) { ++c(); }
counting_value(counting_value const & v)65     counting_value(counting_value const& v) : aa(v.aa), bb(v.bb) { ++c(); }
counting_value(BOOST_RV_REF (counting_value)p)66     counting_value(BOOST_RV_REF(counting_value) p) : aa(p.aa), bb(p.bb) { p.aa = 0; p.bb = 0; ++c(); }                      // Move constructor
operator =(BOOST_RV_REF (counting_value)p)67     counting_value& operator=(BOOST_RV_REF(counting_value) p) { aa = p.aa; p.aa = 0; bb = p.bb; p.bb = 0; return *this; }   // Move assignment
operator =(BOOST_COPY_ASSIGN_REF (counting_value)p)68     counting_value& operator=(BOOST_COPY_ASSIGN_REF(counting_value) p) { aa = p.aa; bb = p.bb; return *this; }              // Copy assignment
~counting_value()69     ~counting_value() { --c(); }
operator ==(counting_value const & v) const70     bool operator==(counting_value const& v) const { return aa == v.aa && bb == v.bb; }
operator <(counting_value const & v) const71     bool operator<(counting_value const& v) const { return aa < v.aa || ( aa == v.aa && bb < v.bb ); }
count()72     static size_t count() { return c(); }
73 
74 private:
c()75     static size_t & c() { static size_t co = 0; return co; }
76     int aa, bb;
77 };
78 
79 namespace boost {
80 
81 template <class T>
82 struct has_nothrow_move;
83 
84 template <>
85 struct has_nothrow_move<counting_value>
86 {
87     static const bool value = true;
88 };
89 
90 }
91 
92 class shptr_value
93 {
94     typedef boost::shared_ptr<int> Ptr;
95 public:
shptr_value(int a=0)96     explicit shptr_value(int a = 0) : m_ptr(new int(a)) {}
operator ==(shptr_value const & v) const97     bool operator==(shptr_value const& v) const { return *m_ptr == *(v.m_ptr); }
operator <(shptr_value const & v) const98     bool operator<(shptr_value const& v) const { return *m_ptr < *(v.m_ptr); }
99 private:
100     boost::shared_ptr<int> m_ptr;
101 };
102 
103 #endif // BOOST_CONTAINER_TEST_STATIC_VECTOR_TEST_HPP
104