Skip to content

Commit 1ccfe50

Browse files
committed
dont repeat yourself
1 parent 6407ad1 commit 1ccfe50

File tree

3 files changed

+73
-74
lines changed

3 files changed

+73
-74
lines changed

include/ankerl/stl.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
///////////////////////// ankerl::unordered_dense::{map, set} /////////////////////////
2+
3+
// A fast & densely stored hashmap and hashset based on robin-hood backward shift deletion.
4+
// Version 4.5.0
5+
// https://github.com/martinus/unordered_dense
6+
//
7+
// Licensed under the MIT License <http://opensource.org/licenses/MIT>.
8+
// SPDX-License-Identifier: MIT
9+
// Copyright (c) 2022-2024 Martin Leitner-Ankerl <[email protected]>
10+
//
11+
// Permission is hereby granted, free of charge, to any person obtaining a copy
12+
// of this software and associated documentation files (the "Software"), to deal
13+
// in the Software without restriction, including without limitation the rights
14+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15+
// copies of the Software, and to permit persons to whom the Software is
16+
// furnished to do so, subject to the following conditions:
17+
//
18+
// The above copyright notice and this permission notice shall be included in all
19+
// copies or substantial portions of the Software.
20+
//
21+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27+
// SOFTWARE.
28+
29+
#ifndef ANKERL_STL_H
30+
#define ANKERL_STL_H
31+
32+
#include <array> // for array
33+
#include <cstdint> // for uint64_t, uint32_t, std::uint8_t, UINT64_C
34+
#include <cstring> // for size_t, memcpy, memset
35+
#include <functional> // for equal_to, hash
36+
#include <initializer_list> // for initializer_list
37+
#include <iterator> // for pair, distance
38+
#include <limits> // for numeric_limits
39+
#include <memory> // for allocator, allocator_traits, shared_ptr
40+
#include <optional> // for optional
41+
#include <stdexcept> // for out_of_range
42+
#include <string> // for basic_string
43+
#include <string_view> // for basic_string_view, hash
44+
#include <tuple> // for forward_as_tuple
45+
#include <type_traits> // for enable_if_t, declval, conditional_t, ena...
46+
#include <utility> // for forward, exchange, pair, as_const, piece...
47+
#include <vector> // for vector
48+
#if ANKERL_UNORDERED_DENSE_HAS_EXCEPTIONS() == 0
49+
# include <cstdlib> // for abort
50+
#endif
51+
52+
#if defined(__has_include)
53+
# if __has_include(<memory_resource>)
54+
# define ANKERL_UNORDERED_DENSE_PMR std::pmr // NOLINT(cppcoreguidelines-macro-usage)
55+
# include <memory_resource> // for polymorphic_allocator
56+
# elif __has_include(<experimental/memory_resource>)
57+
# define ANKERL_UNORDERED_DENSE_PMR std::experimental::pmr // NOLINT(cppcoreguidelines-macro-usage)
58+
# include <experimental/memory_resource> // for polymorphic_allocator
59+
# endif
60+
#endif
61+
62+
#if defined(_MSC_VER) && defined(_M_X64)
63+
# include <intrin.h>
64+
# pragma intrinsic(_umul128)
65+
#endif
66+
67+
#endif

include/ankerl/unordered_dense.h

+3-39
Original file line numberDiff line numberDiff line change
@@ -70,51 +70,15 @@
7070
# define ANKERL_UNORDERED_DENSE_NOINLINE __attribute__((noinline))
7171
#endif
7272

73-
// defined in unordered_dense.cpp
74-
#if defined(ANKERL_UNORDERED_DENSE_EXPORT)
75-
# define ANKERL_UNORDERED_DENSE_DONT_INCLUDE
76-
#else
73+
#if !defined(ANKERL_UNORDERED_DENSE_EXPORT)
7774
# define ANKERL_UNORDERED_DENSE_EXPORT
7875
#endif
7976

8077
#if ANKERL_UNORDERED_DENSE_CPP_VERSION < 201703L
8178
# error ankerl::unordered_dense requires C++17 or higher
8279
#else
83-
# if !defined(ANKERL_UNORDERED_DENSE_DONT_INCLUDE)
84-
# include <array> // for array
85-
# include <cstdint> // for uint64_t, uint32_t, std::uint8_t, UINT64_C
86-
# include <cstring> // for size_t, memcpy, memset
87-
# include <functional> // for equal_to, hash
88-
# include <initializer_list> // for initializer_list
89-
# include <iterator> // for pair, distance
90-
# include <limits> // for numeric_limits
91-
# include <memory> // for allocator, allocator_traits, shared_ptr
92-
# include <optional> // for optional
93-
# include <stdexcept> // for out_of_range
94-
# include <string> // for basic_string
95-
# include <string_view> // for basic_string_view, hash
96-
# include <tuple> // for forward_as_tuple
97-
# include <type_traits> // for enable_if_t, declval, conditional_t, ena...
98-
# include <utility> // for forward, exchange, pair, as_const, piece...
99-
# include <vector> // for vector
100-
# if ANKERL_UNORDERED_DENSE_HAS_EXCEPTIONS() == 0
101-
# include <cstdlib> // for abort
102-
# endif
103-
104-
# if defined(__has_include)
105-
# if __has_include(<memory_resource>)
106-
# define ANKERL_UNORDERED_DENSE_PMR std::pmr // NOLINT(cppcoreguidelines-macro-usage)
107-
# include <memory_resource> // for polymorphic_allocator
108-
# elif __has_include(<experimental/memory_resource>)
109-
# define ANKERL_UNORDERED_DENSE_PMR std::experimental::pmr // NOLINT(cppcoreguidelines-macro-usage)
110-
# include <experimental/memory_resource> // for polymorphic_allocator
111-
# endif
112-
# endif
113-
114-
# if defined(_MSC_VER) && defined(_M_X64)
115-
# include <intrin.h>
116-
# pragma intrinsic(_umul128)
117-
# endif
80+
# if !defined(ANKERL_UNORDERED_DENSE_DONT_INCLUDE_STL)
81+
# include "stl.h"
11882
# endif
11983

12084
# if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__)

src/ankerl.unordered_dense.cpp

+3-35
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,13 @@ module;
66
// to prevent attachment to this module.
77

88
#if !defined(ANKERL_UNORDERED_DENSE_USE_STD_IMPORT)
9-
# include <array> // for array
10-
# include <cstdint> // for uint64_t, uint32_t, uint8_t, UINT64_C
11-
# include <cstring> // for size_t, memcpy, memset
12-
# include <functional> // for equal_to, hash
13-
# include <initializer_list> // for initializer_list
14-
# include <iterator> // for pair, distance
15-
# include <limits> // for numeric_limits
16-
# include <optional> // for optional
17-
# include <memory> // for allocator, allocator_traits, shared_ptr
18-
# include <optional> // for optional
19-
# include <stdexcept> // for out_of_range
20-
# include <string> // for basic_string
21-
# include <string_view> // for basic_string_view, hash
22-
# include <tuple> // for forward_as_tuple
23-
# include <type_traits> // for enable_if_t, declval, conditional_t, ena...
24-
# include <utility> // for forward, exchange, pair, as_const, piece...
25-
# include <vector> // for vector
26-
279
# if defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)
2810
# define ANKERL_UNORDERED_DENSE_HAS_EXCEPTIONS() 1 // NOLINT(cppcoreguidelines-macro-usage)
2911
# else
3012
# define ANKERL_UNORDERED_DENSE_HAS_EXCEPTIONS() 0 // NOLINT(cppcoreguidelines-macro-usage)
3113
# endif
3214

33-
# if ANKERL_UNORDERED_DENSE_HAS_EXCEPTIONS() == 0
34-
# include <cstdlib> // for abort
35-
# endif
36-
37-
# undef ANKERL_UNORDERED_DENSE_HAS_EXCEPTIONS
38-
39-
# if defined(__has_include)
40-
# if __has_include(<memory_resource>)
41-
# include <memory_resource> // for polymorphic_allocator
42-
# elif __has_include(<experimental/memory_resource>)
43-
# include <experimental/memory_resource> // for polymorphic_allocator
44-
# endif
45-
# endif
46-
#else
47-
# include <stdint.h> // for UINT64_C
15+
#include <ankerl/stl.h>
4816
#endif
4917

5018
#if defined(_MSC_VER) && defined(_M_X64)
@@ -59,5 +27,5 @@ import std;
5927
#endif
6028

6129
#define ANKERL_UNORDERED_DENSE_EXPORT export
62-
#define ANKER_UNOREDERED_DENSE_DONT_INCLUDE
63-
#include "ankerl/unordered_dense.h"
30+
#define ANKER_UNOREDERED_DENSE_DONT_INCLUDE_STL
31+
#include <ankerl/unordered_dense.h>

0 commit comments

Comments
 (0)