fmt::internal::declval -> std::declval

This commit is contained in:
Victor Zverovich 2019-05-30 08:34:17 -07:00
parent d07cc2026b
commit 8302c2f33b
7 changed files with 40 additions and 47 deletions

View File

@ -206,10 +206,6 @@
FMT_BEGIN_NAMESPACE
namespace internal {
// An implementation of declval for pre-C++11 compilers such as gcc 4.
template <typename T>
typename std::add_rvalue_reference<T>::type declval() FMT_NOEXCEPT;
template <typename> struct result_of;
#if (__cplusplus >= 201703L || \
@ -350,7 +346,8 @@ typedef char yes[1];
typedef char no[2];
template <typename T, typename V> struct is_constructible {
template <typename U> static yes& test(int (*)[sizeof(new U(declval<V>()))]);
template <typename U>
static yes& test(int (*)[sizeof(new U(std::declval<V>()))]);
template <typename U> static no& test(...);
enum { value = sizeof(test<T>(nullptr)) == sizeof(yes) };
};
@ -602,16 +599,16 @@ using fmt::v5::to_string_view;
template <typename S>
struct is_string
: std::integral_constant<
bool, !std::is_same<dummy_string_view,
decltype(to_string_view(declval<S>()))>::value> {
};
bool,
!std::is_same<dummy_string_view,
decltype(to_string_view(std::declval<S>()))>::value> {};
// Forward declare FILE* specialization defined in color.h
template <> struct is_string<std::FILE*>;
template <> struct is_string<const std::FILE*>;
template <typename S> struct char_t {
typedef decltype(to_string_view(declval<S>())) result;
typedef decltype(to_string_view(std::declval<S>())) result;
typedef typename result::char_type type;
};
@ -1038,8 +1035,8 @@ class locale_ref {
};
template <typename Context, typename T> struct get_type {
typedef decltype(
make_value<Context>(declval<typename std::decay<T>::type&>())) value_type;
typedef decltype(make_value<Context>(
std::declval<typename std::decay<T>::type&>())) value_type;
static const type value = value_type::type_tag;
};

View File

@ -286,7 +286,7 @@ FMT_CONSTEXPR T* end(T (&array)[N]) FMT_NOEXCEPT {
// An implementation of iterator_t for pre-C++20 compilers such as gcc 4.
template <typename T> struct iterator_t {
typedef decltype(internal::begin(internal::declval<const T&>())) type;
typedef decltype(internal::begin(std::declval<const T&>())) type;
};
// For std::result_of in gcc 4.4.
@ -1393,7 +1393,7 @@ template <typename Range, typename ErrorHandler = internal::error_handler>
class arg_formatter_base {
public:
typedef typename Range::value_type char_type;
typedef decltype(internal::declval<Range>().begin()) iterator;
typedef decltype(std::declval<Range>().begin()) iterator;
typedef basic_format_specs<char_type> format_specs;
private:
@ -2388,7 +2388,7 @@ FMT_API void format_system_error(internal::buffer<char>& out, int error_code,
template <typename Range> class basic_writer {
public:
typedef typename Range::value_type char_type;
typedef decltype(internal::declval<Range>().begin()) iterator;
typedef decltype(std::declval<Range>().begin()) iterator;
typedef basic_format_specs<char_type> format_specs;
private:
@ -3427,7 +3427,7 @@ template <typename It> class is_output_iterator {
// The compiler reveals this property only at the point of *actually
// dereferencing* the iterator!
template <typename U>
static decltype(*(internal::declval<U>())) test(std::input_iterator_tag);
static decltype(*(std::declval<U>())) test(std::input_iterator_tag);
template <typename U> static char& test(std::output_iterator_tag);
template <typename U> static const char& test(...);

View File

@ -56,8 +56,8 @@ template <typename Char> struct test_stream : std::basic_ostream<Char> {
template <typename T, typename Char> class is_streamable {
private:
template <typename U>
static decltype((void)(internal::declval<test_stream<Char>&>()
<< internal::declval<U>()),
static decltype((void)(std::declval<test_stream<Char>&>()
<< std::declval<U>()),
std::true_type())
test(int);

View File

@ -539,14 +539,14 @@ struct parts_container_concept_check : std::true_type {
template <typename T> static std::false_type has_add_check(check_second);
template <typename T>
static decltype(
(void)declval<T>().add(declval<typename T::format_part_type>()),
(void)std::declval<T>().add(std::declval<typename T::format_part_type>()),
std::true_type()) has_add_check(check_first);
typedef decltype(has_add_check<PartsContainer>(check_first())) has_add;
static_assert(has_add::value, "PartsContainer doesn't provide add() method");
template <typename T> static std::false_type has_last_check(check_second);
template <typename T>
static decltype((void)declval<T>().last(),
static decltype((void)std::declval<T>().last(),
std::true_type()) has_last_check(check_first);
typedef decltype(has_last_check<PartsContainer>(check_first())) has_last;
static_assert(has_last::value,
@ -555,8 +555,8 @@ struct parts_container_concept_check : std::true_type {
template <typename T>
static std::false_type has_substitute_last_check(check_second);
template <typename T>
static decltype((void)declval<T>().substitute_last(
declval<typename T::format_part_type>()),
static decltype((void)std::declval<T>().substitute_last(
std::declval<typename T::format_part_type>()),
std::true_type()) has_substitute_last_check(check_first);
typedef decltype(has_substitute_last_check<PartsContainer>(
check_first())) has_substitute_last;
@ -565,7 +565,7 @@ struct parts_container_concept_check : std::true_type {
template <typename T> static std::false_type has_begin_check(check_second);
template <typename T>
static decltype((void)declval<T>().begin(),
static decltype((void)std::declval<T>().begin(),
std::true_type()) has_begin_check(check_first);
typedef decltype(has_begin_check<PartsContainer>(check_first())) has_begin;
static_assert(has_begin::value,
@ -573,7 +573,7 @@ struct parts_container_concept_check : std::true_type {
template <typename T> static std::false_type has_end_check(check_second);
template <typename T>
static decltype((void)declval<T>().end(),
static decltype((void)std::declval<T>().end(),
std::true_type()) has_end_check(check_first);
typedef decltype(has_end_check<PartsContainer>(check_first())) has_end;
static_assert(has_end::value, "PartsContainer doesn't provide end() method");
@ -626,19 +626,19 @@ class parts_container {
format_part_type last() { return parts_.back(); }
auto begin() -> decltype(internal::declval<Container>().begin()) {
auto begin() -> decltype(std::declval<Container>().begin()) {
return parts_.begin();
}
auto begin() const -> decltype(internal::declval<const Container>().begin()) {
auto begin() const -> decltype(std::declval<const Container>().begin()) {
return parts_.begin();
}
auto end() -> decltype(internal::declval<Container>().end()) {
auto end() -> decltype(std::declval<Container>().end()) {
return parts_.end();
}
auto end() const -> decltype(internal::declval<const Container>().end()) {
auto end() const -> decltype(std::declval<const Container>().end()) {
return parts_.end();
}

View File

@ -210,7 +210,7 @@ class printf_arg_formatter
typename internal::arg_formatter_base<Range>::iterator>,
public internal::arg_formatter_base<Range> {
public:
typedef decltype(internal::declval<Range>().begin()) iterator;
typedef decltype(std::declval<Range>().begin()) iterator;
private:
typedef typename Range::value_type char_type;

View File

@ -94,21 +94,20 @@ template <typename T, typename _ = void> struct is_range_ : std::false_type {};
#if !FMT_MSC_VER || FMT_MSC_VER > 1800
template <typename T>
struct is_range_<
T, typename std::conditional<
false,
conditional_helper<decltype(internal::declval<T>().begin()),
decltype(internal::declval<T>().end())>,
void>::type> : std::true_type {};
struct is_range_<T, typename std::conditional<
false,
conditional_helper<decltype(std::declval<T>().begin()),
decltype(std::declval<T>().end())>,
void>::type> : std::true_type {};
#endif
/// tuple_size and tuple_element check.
template <typename T> class is_tuple_like_ {
template <typename U>
static auto check(U* p) -> decltype(
std::tuple_size<U>::value,
(void)internal::declval<typename std::tuple_element<0, U>::type>(),
int());
static auto check(U* p)
-> decltype(std::tuple_size<U>::value,
(void)std::declval<typename std::tuple_element<0, U>::type>(),
int());
template <typename> static void check(...);
public:

View File

@ -434,8 +434,8 @@ TEST(PrepareTest, CompileTimePreparedPartsTypeProvider) {
// Use the struct instead of a function to workaround GCC 4.4's 'sorry,
// unimplemented: mangling template_id_expr' issue.
template <typename... Args> struct copied_prepared_format_creator {
static decltype(fmt::prepare<Args...>(fmt::internal::declval<std::string>()))
make(std::string format_str) {
static decltype(fmt::prepare<Args...>(std::declval<std::string>())) make(
std::string format_str) {
auto prepared_format = fmt::prepare<Args...>(std::move(format_str));
auto copied_prepared_format = prepared_format;
prepared_format = fmt::prepare<Args...>("");
@ -513,20 +513,17 @@ class custom_parts_container {
format_part_type last() { return parts_.back(); }
auto begin() -> decltype(fmt::internal::declval<parts>().begin()) {
auto begin() -> decltype(std::declval<parts>().begin()) {
return parts_.begin();
}
auto begin() const
-> decltype(fmt::internal::declval<const parts>().begin()) {
auto begin() const -> decltype(std::declval<const parts>().begin()) {
return parts_.begin();
}
auto end() -> decltype(fmt::internal::declval<parts>().begin()) {
return parts_.end();
}
auto end() -> decltype(std::declval<parts>().begin()) { return parts_.end(); }
auto end() const -> decltype(fmt::internal::declval<const parts>().begin()) {
auto end() const -> decltype(std::declval<const parts>().begin()) {
return parts_.end();
}