summaryrefslogtreecommitdiff
path: root/tiger-compiler/lib/misc/select-const.hh
blob: 23ea6d03d03b30e825f0a7146c4a0296914b2a70 (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
/**
 ** \file misc/select-const.hh
 ** \brief Select between a non const or a const type.
 */

#pragma once

namespace misc
{
  /*------------------.
  | const selectors.  |
  `------------------*/

  /// Return \a T constified.
  template <typename T> struct constify_traits
  {
    using type = const T;
  };

  /// Return \a T as is.
  template <typename T> struct id_traits
  {
    using type = T;
  };

  /*------------------.
  | select_iterator.  |
  `------------------*/

  /// The iterator over a non const structure is plain iterator.
  template <typename T> struct select_iterator
  {
    using type = typename T::iterator;
  };

  /// The iterator over a const structure is a const_iterator.
  template <typename T> struct select_iterator<const T>
  {
    using type = typename T::const_iterator;
  };

} //namespace misc