Vcsn  2.3
Be Rational
index.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional> // std::hash
4 #include <type_traits>
5 
6 namespace vcsn
7 {
8  namespace detail
9  {
11  template <typename Tag>
12  struct index_t_impl
13  {
14  using index_t = unsigned;
15 
16  constexpr index_t_impl(index_t i)
17  : s{i}
18  {}
19 
20  // Disallow index1_t i{index2_t{42}};
21  template <typename T>
22  index_t_impl(index_t_impl<T> t) = delete;
23 
24  bool operator==(index_t_impl t) const
25  {
26  return s == t.s;
27  }
28 
29  // Disallow index1_t{42} == index2_t{42};
30  template <typename T>
31  bool operator==(index_t_impl<T> t) const = delete;
32 
34  index_t_impl() = default;
35  constexpr operator index_t() const { return s; }
37  index_t_impl& operator++() { ++s; return *this; }
39  index_t_impl& operator--() { --s; return *this; }
40 
41  private:
43  };
44  }
45 }
46 
47 namespace std
48 {
50  template <typename Tag>
51  struct hash<vcsn::detail::index_t_impl<Tag>>
52  {
54  size_t operator()(index_t s) const noexcept
55  {
56  return static_cast<size_t>(static_cast<unsigned>(s));
57  }
58  };
59 
63  template <typename Tag>
64  struct is_integral<vcsn::detail::index_t_impl<Tag>>
65  : is_integral<typename vcsn::detail::index_t_impl<Tag>::index_t>
66  {};
67 }
index_t_impl & operator--()
Be compliant with Boost integer ranges.
Definition: index.hh:39
STL namespace.
Lightweight state/transition handle (or index).
Definition: index.hh:12
index_t_impl()=default
Default ctor to please containers.
index_t_impl & operator++()
Be compliant with Boost integer ranges.
Definition: index.hh:37
constexpr index_t_impl(index_t i)
Definition: index.hh:16
bool operator==(index_t_impl t) const
Definition: index.hh:24
Definition: a-star.hh:8
size_t operator()(index_t s) const noexcept
Definition: index.hh:54