File: unordered_flat_map.h

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (102 lines) | stat: -rw-r--r-- 2,963 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2025 GeometryFactory Sarl (France).
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/STL_Extension/include/CGAL/unordered_flat_map.h $
// $Id: include/CGAL/unordered_flat_map.h 08b27d3db14 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s)     : Laurent Rineau

#ifndef CGAL_UNORDERED_FLAT_MAP_H
#define CGAL_UNORDERED_FLAT_MAP_H

#include <CGAL/config.h>

#include <boost/version.hpp>
#if BOOST_VERSION >= 108100 && !defined(CGAL_USE_BOOST_UNORDERED)
#  define CGAL_USE_BOOST_UNORDERED 1
#endif

#if CGAL_USE_BARE_STD_SET
#  define CGAL_USE_BARE_STD_MAP CGAL_USE_BARE_STD_SET
#endif

#if CGAL_USE_BARE_STD_MAP // to benchmark with the ordered std::map
#  include <map>
#  include <set>
#elif CGAL_USE_BOOST_UNORDERED
#  include <boost/unordered/unordered_flat_map.hpp>
#  include <boost/unordered/unordered_flat_set.hpp>
#else // Boost before 1.81.0, use the C++11 std::unordered_map
#  include <boost/unordered_map.hpp>
#  include <boost/unordered_set.hpp>
#endif

#include <functional> // for std::hash, std::equal_to
#include <memory> // for std::allocator

namespace CGAL {

  namespace internal_is_hashable {
    using boost::hash_value;

    template <typename T, typename = void>
    struct Has_hash_value : std::false_type {};

    template <typename T>
    using hash_value_type = decltype(hash_value(std::declval<T>()));
    template <typename T>
    struct Has_hash_value<T, std::void_t<hash_value_type<T>>>
        : std::is_convertible<hash_value_type<T>, std::size_t>
    {};
  }

  template <typename T>
  inline constexpr bool is_hashable_v =
      internal_is_hashable::Has_hash_value<T>::value && std::is_default_constructible_v<std::hash<T>>;

template <
  typename Key,
  typename T,
  typename Hash = std::hash<Key>,
  typename KeyEqual = std::equal_to<Key>,
  typename Allocator = std::allocator<std::pair<const Key, T>>
  >
#if CGAL_USE_BARE_STD_MAP

  using unordered_flat_map = std::map<Key, T, std::less<Key>, Allocator>;

#elif CGAL_USE_BOOST_UNORDERED

  using unordered_flat_map = boost::unordered_flat_map<Key, T, Hash, KeyEqual, Allocator>;

#else // use the Boost implementation of C++11 std::unordered_map (for noexcept)

  using unordered_flat_map = boost::unordered_map<Key, T, Hash, KeyEqual, Allocator>;

#endif

template <
  typename Key,
  typename Hash = std::hash<Key>,
  typename KeyEqual = std::equal_to<Key>,
  typename Allocator = std::allocator<Key>
  >
#if CGAL_USE_BARE_STD_MAP

  using unordered_flat_set = std::set<Key, std::less<Key>, Allocator>;

#elif CGAL_USE_BOOST_UNORDERED

  using unordered_flat_set = boost::unordered_flat_set<Key, Hash, KeyEqual, Allocator>;

#else // use the Boost implementation of C++11 std::unordered_set (for noexcept)

  using unordered_flat_set = boost::unordered_set<Key, Hash, KeyEqual, Allocator>;

#endif

} // end namespace CGAL

#endif // CGAL_UNORDERED_FLAT_MAP_H