diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-04-08 03:09:47 +0000 |
---|---|---|
committer | <> | 2015-05-05 14:37:32 +0000 |
commit | f2541bb90af059680aa7036f315f052175999355 (patch) | |
tree | a5b214744b256f07e1dc2bd7273035a7808c659f /libs/optional/test/testable_classes.hpp | |
parent | ed232fdd34968697a68783b3195b1da4226915b5 (diff) | |
download | boost-tarball-master.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_58_0.tar.bz2.HEADboost_1_58_0master
Diffstat (limited to 'libs/optional/test/testable_classes.hpp')
-rw-r--r-- | libs/optional/test/testable_classes.hpp | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/libs/optional/test/testable_classes.hpp b/libs/optional/test/testable_classes.hpp new file mode 100644 index 000000000..e18359f93 --- /dev/null +++ b/libs/optional/test/testable_classes.hpp @@ -0,0 +1,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 |