]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/histogram/axis/metadata_base.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / histogram / axis / metadata_base.hpp
1 // Copyright 2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 #ifndef BOOST_HISTOGRAM_AXIS_METADATA_BASE_HPP
8 #define BOOST_HISTOGRAM_AXIS_METADATA_BASE_HPP
9
10 #include <boost/core/empty_value.hpp>
11 #include <boost/histogram/detail/relaxed_equal.hpp>
12 #include <boost/histogram/detail/replace_type.hpp>
13 #include <string>
14 #include <type_traits>
15
16 namespace boost {
17 namespace histogram {
18 namespace axis {
19
20 /// Meta data holder with space optimization for empty meta data types.
21 template <class Metadata,
22 class DetailMetadata = detail::replace_default<Metadata, std::string>>
23 class metadata_base : empty_value<DetailMetadata> {
24 using base_t = empty_value<DetailMetadata>;
25
26 protected:
27 using metadata_type = DetailMetadata;
28
29 // std::string explicitly guarantees nothrow only in C++17
30 static_assert(std::is_same<metadata_type, std::string>::value ||
31 std::is_nothrow_move_constructible<metadata_type>::value,
32 "metadata must be nothrow move constructible");
33
34 metadata_base() = default;
35 metadata_base(const metadata_base&) = default;
36 metadata_base& operator=(const metadata_base&) = default;
37
38 // make noexcept because std::string is nothrow move constructible only in C++17
39 metadata_base(metadata_base&& o) noexcept : base_t(std::move(o)) {}
40 metadata_base(metadata_type&& o) noexcept : base_t(empty_init_t{}, std::move(o)) {}
41 // make noexcept because std::string is nothrow move constructible only in C++17
42 metadata_base& operator=(metadata_base&& o) noexcept {
43 base_t::operator=(o);
44 return *this;
45 }
46
47 public:
48 /// Returns reference to metadata.
49 metadata_type& metadata() noexcept { return base_t::get(); }
50
51 /// Returns reference to const metadata.
52 const metadata_type& metadata() const noexcept { return base_t::get(); }
53
54 bool operator==(const metadata_base& o) const noexcept {
55 return detail::relaxed_equal(metadata(), o.metadata());
56 }
57
58 bool operator!=(const metadata_base& o) const noexcept {
59 return operator==(o.metadata());
60 }
61 };
62
63 } // namespace axis
64 } // namespace histogram
65 } // namespace boost
66
67 #endif