Skip to content

Commit

Permalink
add versioning namespace with a test
Browse files Browse the repository at this point in the history
  • Loading branch information
martinus committed Sep 1, 2022
1 parent 9673aa5 commit 3b463e7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/ankerl/unordered_dense.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
#define ANKERL_UNORDERED_DENSE_VERSION_MINOR 3 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible functionality
#define ANKERL_UNORDERED_DENSE_VERSION_PATCH 0 // NOLINT(cppcoreguidelines-macro-usage) backwards compatible bug fixes

// API versioning with inline namespace, see https://www.foonathan.net/2018/11/inline-namespaces/
#define ANKERL_UNORDERED_DENSE_VERSION_CONCAT1(major, minor, patch) v##major##_##minor##_##patch
#define ANKERL_UNORDERED_DENSE_VERSION_CONCAT(major, minor, patch) ANKERL_UNORDERED_DENSE_VERSION_CONCAT1(major, minor, patch)
#define ANKERL_UNORDERED_DENSE_NAMESPACE \
ANKERL_UNORDERED_DENSE_VERSION_CONCAT( \
ANKERL_UNORDERED_DENSE_VERSION_MAJOR, ANKERL_UNORDERED_DENSE_VERSION_MINOR, ANKERL_UNORDERED_DENSE_VERSION_PATCH)

#if defined(_MSVC_LANG)
# define ANKERL_UNORDERED_DENSE_CPP_VERSION _MSVC_LANG
#else
Expand Down Expand Up @@ -90,6 +97,7 @@
# endif

namespace ankerl::unordered_dense {
inline namespace ANKERL_UNORDERED_DENSE_NAMESPACE {

// hash ///////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -1347,6 +1355,7 @@ using set = detail::table<Key, void, Hash, KeyEqual, std::pmr::polymorphic_alloc
// deduction guides for alias templates are only possible since C++20
// see https://en.cppreference.com/w/cpp/language/class_template_argument_deduction

} // namespace ANKERL_UNORDERED_DENSE_NAMESPACE
} // namespace ankerl::unordered_dense

// std extensions /////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ test_sources = [
'unit/max.cpp',
'unit/move_to_moved.cpp',
'unit/multiple_apis.cpp',
'unit/namespace.cpp',
'unit/not_copyable.cpp',
'unit/not_moveable.cpp',
'unit/pmr.cpp',
Expand Down
11 changes: 11 additions & 0 deletions test/unit/namespace.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <ankerl/unordered_dense.h>

#include <doctest.h>

static_assert(std::is_same_v<ankerl::unordered_dense::v1_3_0::map<int, int>, ankerl::unordered_dense::map<int, int>>);
static_assert(std::is_same_v<ankerl::unordered_dense::v1_3_0::hash<int>, ankerl::unordered_dense::hash<int>>);

TEST_CASE("version_namespace") {
auto map = ankerl::unordered_dense::v1_3_0::map<int, int>{};
REQUIRE(map.empty());
}

0 comments on commit 3b463e7

Please sign in to comment.