Skip to content

Commit

Permalink
string_view is now always available.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluescarni committed Jan 17, 2021
1 parent 96024bd commit 8c57ee8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 42 deletions.
8 changes: 0 additions & 8 deletions config.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@

#endif

// Detect the availability of std::string_view.
// Use the definition from mp++.
#if defined(MPPP_HAVE_STRING_VIEW)

#define OBAKE_HAVE_STRING_VIEW

#endif

// For packing 64-bit values, we need 128-bit multiplication.
// This requires either 128-bit integer types, or compiler intrinsics.
// NOTE: _WIN64 should catch also 64-bit arm.
Expand Down
15 changes: 3 additions & 12 deletions include/obake/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@
#include <iterator>
#include <ostream>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <utility>

#if defined(OBAKE_HAVE_STRING_VIEW)

#include <string_view>

#endif

namespace obake
{

Expand Down Expand Up @@ -275,13 +270,9 @@ using is_string_like = ::std::disjunction<
// Is it an array of chars?
// NOTE: std::remove_cv_t does remove cv qualifiers from arrays.
::std::conjunction<::std::is_array<::std::remove_cv_t<T>>,
::std::is_same<::std::remove_extent_t<::std::remove_cv_t<T>>, char>>
#if defined(OBAKE_HAVE_STRING_VIEW)
,
::std::is_same<::std::remove_extent_t<::std::remove_cv_t<T>>, char>>,
// Is it a string view?
::std::is_same<::std::remove_cv_t<T>, ::std::string_view>
#endif
>;
::std::is_same<::std::remove_cv_t<T>, ::std::string_view>>;

template <typename T>
inline constexpr bool is_string_like_v = is_string_like<T>::value;
Expand Down
11 changes: 1 addition & 10 deletions test/polynomials_polynomial_00.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@
#include <initializer_list>
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <type_traits>

#if defined(OBAKE_HAVE_STRING_VIEW)

#include <string_view>

#endif

#include <mp++/integer.hpp>

#include <obake/detail/tuple_for_each.hpp>
Expand Down Expand Up @@ -60,12 +55,10 @@ TEST_CASE("make_polynomials_test")
REQUIRE(b.get_symbol_set() == symbol_set{"b"});
}

#if defined(OBAKE_HAVE_STRING_VIEW)
{
auto [a] = make_polynomials<poly_t>(std::string_view{"a"});
REQUIRE(a.get_symbol_set() == symbol_set{"a"});
}
#endif

{
auto [a1] = make_polynomials<poly_t>(symbol_set{"a"}, "a");
Expand All @@ -79,7 +72,6 @@ TEST_CASE("make_polynomials_test")
REQUIRE(c.get_symbol_set() == symbol_set{"a", "b", "c"});
}

#if defined(OBAKE_HAVE_STRING_VIEW)
{
auto [a1] = make_polynomials<poly_t>(symbol_set{"a"}, std::string_view{"a"});
REQUIRE(a1.get_symbol_set() == symbol_set{"a"});
Expand All @@ -88,7 +80,6 @@ TEST_CASE("make_polynomials_test")
REQUIRE(b.get_symbol_set() == symbol_set{"a", "b", "c"});
REQUIRE(c.get_symbol_set() == symbol_set{"a", "b", "c"});
}
#endif

OBAKE_REQUIRES_THROWS_CONTAINS(make_polynomials<poly_t>(symbol_set{"b"}, "a"), std::invalid_argument,
"Cannot create a polynomial with symbol set {'b'} from the generator 'a': the "
Expand Down
13 changes: 1 addition & 12 deletions test/type_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <thread>
#include <type_traits>
#include <unordered_map>
#include <vector>

#if defined(OBAKE_HAVE_STRING_VIEW)

#include <string_view>

#endif

#include <obake/detail/limits.hpp>
#include <obake/type_traits.hpp>

Expand Down Expand Up @@ -311,12 +306,10 @@ TEST_CASE("is_string_like_v")
REQUIRE(is_string_like_v<const char[2]>);
REQUIRE(!is_string_like_v<char(&&)[10]>);

#if defined(OBAKE_HAVE_STRING_VIEW)
REQUIRE(is_string_like_v<std::string_view>);
REQUIRE(!is_string_like_v<std::string_view &>);
REQUIRE(!is_string_like_v<const std::string_view &>);
REQUIRE(is_string_like_v<const std::string_view>);
#endif

#if defined(OBAKE_HAVE_CONCEPTS)
REQUIRE(!StringLike<void>);
Expand All @@ -325,9 +318,7 @@ TEST_CASE("is_string_like_v")
REQUIRE(!StringLike<char *&>);
REQUIRE(!StringLike<const char(&)[10]>);
REQUIRE(StringLike<std::string>);
#if defined(OBAKE_HAVE_STRING_VIEW)
REQUIRE(StringLike<std::string_view>);
#endif
REQUIRE(!StringLike<std::string &>);
#endif

Expand All @@ -342,12 +333,10 @@ TEST_CASE("is_string_like_v")
char s2[] = "blab";
check_string_like_dispatch(s2);
check_string_like_dispatch(&s2[0]);
#if defined(OBAKE_HAVE_STRING_VIEW)
const std::string_view sv1{"bubbbbba"};
check_string_like_dispatch(sv1);
std::string_view sv2{"bubbbba"};
check_string_like_dispatch(sv2);
#endif
}

struct nonaddable_0 {
Expand Down

0 comments on commit 8c57ee8

Please sign in to comment.