summaryrefslogtreecommitdiff
path: root/libs/optional/test/testable_classes.hpp
blob: e18359f93e9dda9f3d663a6523ec5009dd540201 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (C) 2014 Andrzej Krzemienski.
//
// Use, modification, and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/optional for documentation.
//
// You are welcome to contact the author at:
//  akrzemi1@gmail.com

#ifndef BOOST_OPTIONAL_TEST_TESTABKE_CLASSES_AK_07JAN2015_HPP
#define BOOST_OPTIONAL_TEST_TESTABKE_CLASSES_AK_07JAN2015_HPP

struct ScopeGuard // no copy/move ctor/assign
{
  int val_;
  explicit ScopeGuard(int v) : val_(v) {}
  int& val() { return val_; }
  const int& val() const { return val_; }
  
private:
  ScopeGuard(ScopeGuard const&);
  void operator=(ScopeGuard const&);
};

struct Abstract
{
  virtual int& val() = 0;
  virtual const int& val() const = 0;
  virtual ~Abstract() {}
  Abstract(){}
  
private:
  Abstract(Abstract const&);
  void operator=(Abstract const&);
};

struct Impl : Abstract
{
  int val_;
  Impl(int v) : val_(v) {}
  int& val() { return val_; }
  const int& val() const { return val_; }
};

template <typename T>
struct concrete_type_of
{
  typedef T type;
};

template <>
struct concrete_type_of<Abstract>
{
  typedef Impl type;
};

template <>
struct concrete_type_of<const Abstract>
{
  typedef const Impl type;
};

template <typename T>
struct has_arrow
{
  static const bool value = true;
};

template <>
struct has_arrow<int>
{
  static const bool value = false;
};

int& val(int& i) { return i; }
int& val(Abstract& a) { return a.val(); }
int& val(ScopeGuard& g) { return g.val(); }

const int& val(const int& i) { return i; }
const int& val(const Abstract& a) { return a.val(); }
const int& val(const ScopeGuard& g) { return g.val(); }

bool operator==(const Abstract& l, const Abstract& r) { return l.val() == r.val(); }
bool operator==(const ScopeGuard& l, const ScopeGuard& r) { return l.val() == r.val(); }

bool operator<(const Abstract& l, const Abstract& r) { return l.val() < r.val(); }
bool operator<(const ScopeGuard& l, const ScopeGuard& r) { return l.val() < r.val(); }

#endif //BOOST_OPTIONAL_TEST_TESTABKE_CLASSES_AK_07JAN2015_HPP