Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ endif()



option(TSL_ORDERED_MAP_BUILD_MODULE "Build the C++20 module for tsl::ordered_map" OFF)

if(TSL_ORDERED_MAP_BUILD_MODULE)
if(CMAKE_CXX_STANDARD LESS 20)
message(FATAL_ERROR "TSL_ORDERED_MAP_BUILD_MODULE requires C++20 or later (CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD})")
endif()

add_library(ordered_map_module)
add_library(tsl::ordered_map_module ALIAS ordered_map_module)

target_sources(ordered_map_module
PUBLIC FILE_SET CXX_MODULES FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/tsl.ordered_map.cppm")

target_link_libraries(ordered_map_module PUBLIC tsl::ordered_map)
set_target_properties(ordered_map_module PROPERTIES CXX_STANDARD 20)

install(TARGETS ordered_map_module
EXPORT tsl-ordered-mapTargets
FILE_SET CXX_MODULES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
endif()

include(CMakePackageConfigHelpers)

## Install include directory and potential natvis file
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Two classes are provided: `tsl::ordered_map` and `tsl::ordered_set`.
- Support for efficient serialization and deserialization (see [example](#serialization) and the `serialize/deserialize` methods in the [API](https://tessil.github.io/ordered-map/classtsl_1_1ordered__map.html) for details).
- The library can be used with exceptions disabled (through `-fno-exceptions` option on Clang and GCC, without an `/EH` option on MSVC or simply by defining `TSL_NO_EXCEPTIONS`). `std::terminate` is used in replacement of the `throw` instruction when exceptions are disabled.
- API closely similar to `std::unordered_map` and `std::unordered_set`.
- Support for C++ modules (requires C++20 or later)

### Differences compared to `std::unordered_map`
`tsl::ordered_map` tries to have an interface similar to `std::unordered_map`, but some differences exist.
Expand Down Expand Up @@ -82,6 +83,8 @@ cmake --build .
./tsl_ordered_map_tests
```

To enable C++ modules, the version must be at least C++20 on any compiler supporting C++ modules (minimal versions usually Clang 18, GCC 15, and MSVC 17). When configuring CMake, pass `-DTSL_ORDERED_MAP_BUILD_MODULE=ON` to enable the `TSL_ORDERED_MAP_BUILD_MODULE` option. This creates a module `tsl.ordered_map`, which exports `tsl::ordered_map` and `tsl::ordered_set`.

### Usage

The API can be found [here](https://tessil.github.io/ordered-map/).
Expand Down
4 changes: 2 additions & 2 deletions include/tsl/ordered_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const T& clamp(const T& v, const T& lo, const T& hi) {
}

template <typename T, typename U>
static T numeric_cast(U value,
T numeric_cast(U value,
const char* error_message = "numeric_cast() failed.") {
T ret = static_cast<T>(value);
if (static_cast<U>(ret) != value) {
Expand Down Expand Up @@ -145,7 +145,7 @@ static_assert(std::numeric_limits<slz_size_type>::max() >=
"slz_size_type must be >= std::size_t");

template <class T, class Deserializer>
static T deserialize_value(Deserializer& deserializer) {
T deserialize_value(Deserializer& deserializer) {
// MSVC < 2017 is not conformant, circumvent the problem by removing the
// template keyword
#if defined(_MSC_VER) && _MSC_VER < 1910
Expand Down
34 changes: 34 additions & 0 deletions src/tsl.ordered_map.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* MIT License
*
* Copyright (c) 2017 Thibaut Goetghebuer-Planchon <tessil@gmx.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
module;

#include "tsl/ordered_map.h"
#include "tsl/ordered_set.h"

export module tsl.ordered_map;

export namespace tsl {
using tsl::ordered_map;
using tsl::ordered_set;
}