Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to C++17 #71

Merged
merged 10 commits into from
Oct 23, 2024
Merged
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
8 changes: 0 additions & 8 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ skip_commits:

environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
GENERATOR: Visual Studio 14 2015
CXX_STANDARD: 11

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
GENERATOR: Visual Studio 15 2017
CXX_STANDARD: 14

- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
GENERATOR: Visual Studio 16 2019
CXX_STANDARD: 17
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/test-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,10 @@ jobs:
cmake_options: "-DUPA_AMALGAMATED=ON -DUPA_BUILD_EXAMPLES=ON"
before_cmake: tools/amalgamate.sh

- name: g++-9 C++14
- name: g++-9 C++17
os: ubuntu-22.04
cxx_compiler: g++-9
cxx_standard: 14
cmake_options: "-DUPA_BUILD_EXAMPLES=ON"

- name: g++-9 C++11
os: ubuntu-22.04
cxx_compiler: g++-9
cxx_standard: 11
cxx_standard: 17
cmake_options: "-DUPA_BUILD_EXAMPLES=ON"

steps:
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ jobs:
cxx_standard: 20
cmake_options: ""

- name: VS 2022 C++14
- name: VS 2022 C++17
os: windows-2022
generator: "Visual Studio 17 2022"
cxx_standard: 14
cxx_standard: 17
cmake_options: ""

- name: VS 2022 C++17
- name: VS 2022 C++20
os: windows-2022
generator: "Visual Studio 17 2022"
cxx_standard: 17
cxx_standard: 20
cmake_options: ""

- name: VS 2022 C++23
Expand All @@ -38,6 +38,12 @@ jobs:
cxx_standard: 23
cmake_options: ""

- name: VS 2022 Clang C++17
os: windows-2022
generator: "Visual Studio 17 2022"
cxx_standard: 17
cmake_options: "-T ClangCL"

- name: VS 2022 Clang C++20
os: windows-2022
generator: "Visual Studio 17 2022"
Expand Down
13 changes: 2 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(upa_lib_export url)
set(upa_lib_target upa_url)

if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

Expand All @@ -49,7 +49,6 @@ option(UPA_BUILD_BENCH "Build the Upa URL benchmarks." OFF)
option(UPA_BUILD_FUZZER "Build the Upa URL fuzzer." OFF)
option(UPA_BUILD_EXAMPLES "Build the Upa URL examples." OFF)
option(UPA_BUILD_EXTRACTED "Build Upa URL examples extracted from the docs." OFF)
option(UPA_BUILD_TOOLS "Build tools." OFF)
option(UPA_INSTALL "Generate the install target." ON)
# library options
option(UPA_AMALGAMATED "Use amalgamated URL library source." OFF)
Expand Down Expand Up @@ -119,7 +118,7 @@ include_directories(deps)

# Is the Upa URL library needed?
if (UPA_BUILD_TESTS OR UPA_BUILD_BENCH OR UPA_BUILD_FUZZER OR UPA_BUILD_EXAMPLES OR
UPA_BUILD_EXTRACTED OR UPA_INSTALL OR NOT UPA_BUILD_TOOLS)
UPA_BUILD_EXTRACTED OR UPA_INSTALL)
if (UPA_AMALGAMATED)
add_library(${upa_lib_target} STATIC
single_include/upa/url.cpp)
Expand Down Expand Up @@ -238,14 +237,6 @@ if (UPA_BUILD_EXTRACTED)
add_subdirectory(examples/extracted-cpp)
endif()

# Tool's targets

if (UPA_BUILD_TOOLS)
add_executable(dumpCharBitSets tools/dumpCharBitSets.cpp)
set_property(TARGET dumpCharBitSets PROPERTY CXX_STANDARD 17)
target_include_directories(dumpCharBitSets PRIVATE include)
endif()

# Install

if (UPA_INSTALL AND NOT UPA_AMALGAMATED)
Expand Down
4 changes: 2 additions & 2 deletions examples/urlparse.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2016-2023 Rimas Misevičius
// Copyright 2016-2024 Rimas Misevičius
// Distributed under the BSD-style license that can be
// found in the LICENSE file.
//
Expand Down Expand Up @@ -228,7 +228,7 @@ void read_samples(const char* file_name, SamplesOutput& out)
if (line.empty())
break;
state = State::header;
UPA_FALLTHROUGH
[[fallthrough]];
case State::header: {
bool ok = true;
auto icolon = line.find(':');
Expand Down
32 changes: 6 additions & 26 deletions include/upa/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,17 @@
#ifndef UPA_CONFIG_H
#define UPA_CONFIG_H

#ifdef __has_include
# if __has_include(<version>)
# include <version> // IWYU pragma: export
# endif
#if __has_include(<version>)
# include <version> // IWYU pragma: export
#endif

// Define UPA_CPP_20 if compiler supports C++20 or later standard
// Macros for compilers that support the C++20 or later standard
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG) ? (_MSVC_LANG >= 202002) : (__cplusplus >= 202002)
# define UPA_CPP_20
#endif

// Define UPA_CPP_17 if compiler supports C++17 or later standard
// https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
#if defined(_MSVC_LANG) ? (_MSVC_LANG >= 201703) : (__cplusplus >= 201703)
# define UPA_CPP_17
# define UPA_FALLTHROUGH [[fallthrough]];
# define UPA_CONSTEXPR_17 constexpr
# define UPA_NOEXCEPT_17 noexcept
#else
# define UPA_FALLTHROUGH
# define UPA_CONSTEXPR_17 inline
# define UPA_NOEXCEPT_17
#endif

// Define UPA_CPP_14 if compiler supports C++14 or later
// Note: Visual Studio 2015 (14.0; _MSC_VER == 1900) lacks sufficient C++14 support
#if defined(_MSVC_LANG) ? (_MSVC_LANG >= 201402 && _MSC_VER > 1900) : (__cplusplus >= 201402)
# define UPA_CPP_14
# define UPA_CONSTEXPR_14 constexpr
# define UPA_CONSTEXPR_20 constexpr
#else
# define UPA_CONSTEXPR_14 inline
# define UPA_CONSTEXPR_20 inline
#endif

// Barrier for pointer anti-aliasing optimizations even across function boundaries.
Expand Down
85 changes: 37 additions & 48 deletions include/upa/str_arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,36 @@ inline void procfn(Args&&... args) {
#ifndef UPA_STR_ARG_H
#define UPA_STR_ARG_H

#include "config.h"
#include "url_utf.h"
#include <cassert>
#include <cstddef>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>

#ifdef UPA_CPP_17
# include <string_view>
# define UPA_STRING_VIEW_TYPE std::string_view
#else
# include "str_view.h"
# define UPA_STRING_VIEW_TYPE upa::str_view<char>
#endif

namespace upa {

// String view type

using string_view = UPA_STRING_VIEW_TYPE;
using string_view = std::string_view;

// Supported char and size types

template<class CharT>
struct is_char_type : std::integral_constant<bool,
std::is_same<CharT, char>::value ||
constexpr bool is_char_type_v =
std::is_same_v<CharT, char> ||
#ifdef __cpp_char8_t
std::is_same<CharT, char8_t>::value ||
std::is_same_v<CharT, char8_t> ||
#endif
std::is_same<CharT, char16_t>::value ||
std::is_same<CharT, char32_t>::value ||
std::is_same<CharT, wchar_t>::value
> {};
std::is_same_v<CharT, char16_t> ||
std::is_same_v<CharT, char32_t> ||
std::is_same_v<CharT, wchar_t>;

template<class SizeT>
struct is_size_type : std::integral_constant<bool,
std::is_convertible<SizeT, std::size_t>::value ||
std::is_convertible<SizeT, std::ptrdiff_t>::value
> {};
constexpr bool is_size_type_v =
std::is_convertible_v<SizeT, std::size_t> ||
std::is_convertible_v<SizeT, std::ptrdiff_t>;


// string args helper class
Expand All @@ -70,14 +60,14 @@ class str_arg {
// output value type
using value_type =
// wchar_t type will be converted to char16_t or char32_t type equivalent by size
typename std::conditional<std::is_same<CharT, wchar_t>::value, std::conditional<sizeof(wchar_t) == sizeof(char16_t), char16_t, char32_t>::type,
std::conditional_t<std::is_same_v<CharT, wchar_t>, std::conditional_t<sizeof(wchar_t) == sizeof(char16_t), char16_t, char32_t>,
#ifdef __cpp_char8_t
// char8_t type will be converted to char type
typename std::conditional<std::is_same<CharT, char8_t>::value, char, input_type>::type
std::conditional_t<std::is_same_v<CharT, char8_t>, char, input_type>
#else
input_type
#endif
>::type;
>;

// constructors
str_arg(const str_arg&) noexcept = default;
Expand Down Expand Up @@ -131,7 +121,7 @@ class str_arg {
// String type helpers

template<class T>
using remove_cvptr_t = typename std::remove_cv<typename std::remove_pointer<T>::type>::type;
using remove_cvptr_t = std::remove_cv_t<std::remove_pointer_t<T>>;

namespace detail {
// See: https://stackoverflow.com/a/9154394
Expand Down Expand Up @@ -177,8 +167,8 @@ struct str_arg_char<CharT*, CharT*> : std::remove_cv<CharT> {
// pointer and size
template<class CharT, class SizeT>
struct str_arg_char<CharT*, SizeT> : std::enable_if<
is_size_type<SizeT>::value,
typename std::remove_cv<CharT>::type> {
is_size_type_v<SizeT>,
std::remove_cv_t<CharT>> {

template <typename T>
static str_arg<T> to_str_arg(const T* s, std::size_t length) {
Expand All @@ -199,8 +189,8 @@ struct str_arg_char<CharT*> : std::remove_cv<CharT> {
// one string class argument
template<class StrT>
struct str_arg_char<StrT> : std::enable_if<
std::is_pointer<detail::data_member_t<StrT>>::value &&
is_size_type<detail::length_member_t<StrT>>::value,
std::is_pointer_v<detail::data_member_t<StrT>> &&
is_size_type_v<detail::length_member_t<StrT>>,
remove_cvptr_t<detail::data_member_t<StrT>>> {

template <class STR, typename T = typename STR::value_type>
Expand All @@ -213,16 +203,16 @@ struct str_arg_char<StrT> : std::enable_if<
// String arguments helper types

template<class ...Args>
using str_arg_char_s = str_arg_char<typename std::decay<Args>::type...>;
using str_arg_char_s = str_arg_char<std::decay_t<Args>...>;

template<class ...Args>
using str_arg_char_t = typename str_arg_char_s<Args...>::type;


template<class ...Args>
using enable_if_str_arg_t = typename std::enable_if<
is_char_type<str_arg_char_t<Args...>>::value,
int>::type;
using enable_if_str_arg_t = std::enable_if_t<
is_char_type_v<str_arg_char_t<Args...>>,
int>;


// String arguments helper function
Expand All @@ -236,29 +226,28 @@ inline auto make_str_arg(Args&&... args) -> str_arg<str_arg_char_t<Args...>> {
// Convert to std::string or string_view

template<class CharT>
struct is_char8_type : std::integral_constant<bool,
std::is_same<CharT, char>::value
constexpr bool is_char8_type_v =
std::is_same_v<CharT, char>
#ifdef __cpp_char8_t
|| std::is_same<CharT, char8_t>::value
|| std::is_same_v<CharT, char8_t>
#endif
> {};
;

template<class ...Args>
using enable_if_str_arg_to_char8_t = typename std::enable_if<
is_char8_type<str_arg_char_t<Args...>>::value,
int>::type;
using enable_if_str_arg_to_char8_t = std::enable_if_t<
is_char8_type_v<str_arg_char_t<Args...>>,
int>;

template<class CharT>
struct is_charW_type : std::integral_constant<bool,
std::is_same<CharT, char16_t>::value ||
std::is_same<CharT, char32_t>::value ||
std::is_same<CharT, wchar_t>::value
> {};
constexpr bool is_charW_type_v =
std::is_same_v<CharT, char16_t> ||
std::is_same_v<CharT, char32_t> ||
std::is_same_v<CharT, wchar_t>;

template<class ...Args>
using enable_if_str_arg_to_charW_t = typename std::enable_if<
is_charW_type<str_arg_char_t<Args...>>::value,
int>::type;
using enable_if_str_arg_to_charW_t = std::enable_if_t<
is_charW_type_v<str_arg_char_t<Args...>>,
int>;


inline std::string&& make_string(std::string&& str) {
Expand Down
Loading