Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
StrongIndex.h
Go to the documentation of this file.
1 
7 #ifndef INCLUDE_MOLASSEMBLER_TEMPLE_STRONG_INDEX_H
8 #define INCLUDE_MOLASSEMBLER_TEMPLE_STRONG_INDEX_H
9 
11 #include "boost/functional/hash.hpp"
12 #include <tuple>
13 
14 namespace Scine {
15 namespace Molassembler {
16 namespace Temple {
17 
36 template<typename Tag, typename T>
37 class StrongIndex : public Crtp::LexicographicComparable<StrongIndex<Tag, T>> {
38 public:
39  using value_type = T;
40  using Hash = boost::hash<StrongIndex<Tag, T>>;
41 
43  constexpr StrongIndex() = default;
45  constexpr explicit StrongIndex(T v) : v_(v) {}
46  constexpr StrongIndex(const StrongIndex& other) = default;
47  constexpr StrongIndex(StrongIndex&& other) = default;
48  constexpr StrongIndex& operator = (const StrongIndex& other) noexcept = default;
49  constexpr StrongIndex& operator = (StrongIndex&& other) noexcept = default;
50 
52  constexpr StrongIndex& operator = (const T& v) { v_ = v; return *this; }
53 
54  /* Implicit conversion operators */
55  constexpr operator T& () noexcept { return v_; }
56  constexpr operator const T& () const noexcept { return v_; }
57 
58  constexpr auto tie() const { return std::tie(v_); }
59 
60 private:
61  T v_;
62 };
63 
75 template<typename Tag, typename T>
76 std::size_t hash_value(const StrongIndex<Tag, T>& v) {
77  return boost::hash<T>{}(v);
78 }
79 
80 } // namespace Temple
81 } // namespace Molassembler
82 } // namespace Scine
83 
84 #endif
Generates all operators using a method returning a tuple.
Definition: OperatorSuppliers.h:84
Type helper for creating strong index types that are type-level distinct from their fundamental types...
Definition: StrongIndex.h:37
Operator-supplying CRTP base classes.
constexpr StrongIndex()=default
Default constructor does not value initialize.
constexpr StrongIndex(T v)
Explicit value initialization.
Definition: StrongIndex.h:45
std::size_t hash_value(const StrongIndex< Tag, T > &v)
Hash support function for strong index types.
Definition: StrongIndex.h:76