using std::span from c++20

- Added the ability to use span from std when standard 20 is enabled.
- Previous catch version didn't work with 20 standard.
This commit is contained in:
Egor Kuzmin 2020-11-05 10:34:56 +03:00
parent 6ac13af81a
commit 85ff00a004
13 changed files with 6768 additions and 1923 deletions

View File

@ -4,6 +4,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
option(UUID_BUILD_TESTS "Build the unit tests" ON)
option(UUID_SYSTEM_GENERATOR "Enable operating system uuid generator" ON)
option(UUID_USING_CXX20_SPAN "Using span from std instead of gsl" OFF)
# Library target
add_library(${PROJECT_NAME} INTERFACE)
@ -26,6 +27,11 @@ if (UUID_SYSTEM_GENERATOR)
endif ()
endif ()
# Using span from std
if (NOT UUID_USING_CXX20_SPAN)
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_SOURCE_DIR}/gsl)
endif ()
# Tests
if (UUID_BUILD_TESTS)
add_subdirectory(test)

File diff suppressed because it is too large Load Diff

View File

@ -17,13 +17,13 @@
#ifndef GSL_GSL_H
#define GSL_GSL_H
#include <gsl/gsl_algorithm> // copy
#include <gsl/gsl_assert> // Ensures/Expects
#include <gsl/gsl_byte> // byte
#include <gsl/gsl_util> // finally()/narrow()/narrow_cast()...
#include <gsl/multi_span> // multi_span, strided_span...
#include <gsl/pointers> // owner, not_null
#include <gsl/span> // span
#include <gsl/string_span> // zstring, string_span, zstring_builder...
#include "gsl_algorithm" // copy
#include "gsl_assert" // Ensures/Expects
#include "gsl_byte" // byte
#include "gsl_util" // finally()/narrow()/narrow_cast()...
#include "multi_span" // multi_span, strided_span...
#include "pointers" // owner, not_null
#include "span" // span
#include "string_span" // zstring, string_span, zstring_builder...
#endif // GSL_GSL_H

View File

@ -17,8 +17,8 @@
#ifndef GSL_ALGORITHM_H
#define GSL_ALGORITHM_H
#include <gsl/gsl_assert> // for Expects
#include <gsl/span> // for dynamic_extent, span
#include "gsl_assert" // for Expects
#include "span" // for dynamic_extent, span
#include <algorithm> // for copy_n
#include <cstddef> // for ptrdiff_t

View File

@ -17,7 +17,7 @@
#ifndef GSL_UTIL_H
#define GSL_UTIL_H
#include <gsl/gsl_assert> // for Expects
#include "gsl_assert" // for Expects
#include <array>
#include <cstddef> // for ptrdiff_t, size_t

View File

@ -17,9 +17,9 @@
#ifndef GSL_MULTI_SPAN_H
#define GSL_MULTI_SPAN_H
#include <gsl/gsl_assert> // for Expects
#include <gsl/gsl_byte> // for byte
#include <gsl/gsl_util> // for narrow_cast
#include "gsl_assert" // for Expects
#include "gsl_byte" // for byte
#include "gsl_util" // for narrow_cast
#include <algorithm> // for transform, lexicographical_compare
#include <array> // for array

View File

@ -17,7 +17,7 @@
#ifndef GSL_POINTERS_H
#define GSL_POINTERS_H
#include <gsl/gsl_assert> // for Ensures, Expects
#include "gsl_assert" // for Ensures, Expects
#include <algorithm> // for forward
#include <iosfwd> // for ptrdiff_t, nullptr_t, ostream, size_t

View File

@ -17,9 +17,9 @@
#ifndef GSL_SPAN_H
#define GSL_SPAN_H
#include <gsl/gsl_assert> // for Expects
#include <gsl/gsl_byte> // for byte
#include <gsl/gsl_util> // for narrow_cast, narrow
#include "gsl_assert" // for Expects
#include "gsl_byte" // for byte
#include "gsl_util" // for narrow_cast, narrow
#include <algorithm> // for lexicographical_compare
#include <array> // for array

View File

@ -17,9 +17,9 @@
#ifndef GSL_STRING_SPAN_H
#define GSL_STRING_SPAN_H
#include <gsl/gsl_assert> // for Ensures, Expects
#include <gsl/gsl_util> // for narrow_cast
#include <gsl/span> // for operator!=, operator==, dynamic_extent
#include "gsl_assert" // for Ensures, Expects
#include "gsl_util" // for narrow_cast
#include "span" // for operator!=, operator==, dynamic_extent
#include <algorithm> // for equal, lexicographical_compare
#include <array> // for array

View File

@ -15,7 +15,7 @@
#include <chrono>
#include <numeric>
#include <atomic>
#include <gsl/span>
#include <span>
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
@ -50,6 +50,14 @@
namespace uuids
{
#ifdef __cpp_lib_span
template <class ElementType, std::size_t Extent>
using span = std::span<ElementType, Extent>;
#else
template <class ElementType, std::ptrdiff_t Extent>
using span = gsl::span<ElementType, Extent>;
#endif
namespace detail
{
template <typename TChar>
@ -352,7 +360,7 @@ namespace uuids
std::copy(std::cbegin(arr), std::cend(arr), std::begin(data));
}
explicit uuid(gsl::span<value_type, 16> bytes)
explicit uuid(span<value_type, 16> bytes)
{
std::copy(std::cbegin(bytes), std::cend(bytes), std::begin(data));
}
@ -403,9 +411,9 @@ namespace uuids
data.swap(other.data);
}
inline gsl::span<std::byte const, 16> as_bytes() const
inline span<std::byte const, 16> as_bytes() const
{
return gsl::span<std::byte const, 16>(reinterpret_cast<std::byte const*>(data.data()), 16);
return span<std::byte const, 16>(reinterpret_cast<std::byte const*>(data.data()), 16);
}
template<class CharT = char>

View File

@ -4,15 +4,19 @@ enable_testing()
add_executable(test_${PROJECT_NAME} main.cpp test_generators.cpp test_uuid.cpp)
target_include_directories(test_${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/catch)
target_link_libraries(test_${PROJECT_NAME} PRIVATE ${PROJECT_NAME})
set_target_properties(test_${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
if(WIN32)
if (UUID_USING_CXX20_SPAN)
set_target_properties(test_${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
else ()
set_target_properties(test_${PROJECT_NAME} PROPERTIES CXX_STANDARD 17)
endif ()
if (WIN32)
target_compile_options(test_${PROJECT_NAME} PRIVATE /EHc)
target_compile_definitions(test_${PROJECT_NAME} PRIVATE _SCL_SECURE_NO_WARNINGS)
elseif(APPLE)
elseif (APPLE)
target_compile_options(test_${PROJECT_NAME} PRIVATE -fexceptions -g -Wall)
else()
else ()
target_compile_options(test_${PROJECT_NAME} PRIVATE -fexceptions -g -Wall)
endif()
endif ()
get_target_property(CURRENT_COMPILE_OPTIONS test_${PROJECT_NAME} COMPILE_OPTIONS)
message(STATUS "** ${CMAKE_CXX_COMPILER_ID} flags: ${CURRENT_COMPILE_OPTIONS}")