Skip to content

Commit a0c7234

Browse files
committed
Provide reasonable default definition for is_contiguous
1 parent d2a159f commit a0c7234

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

include/fmt/base.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@
8787
# define FMT_HAS_CPP_ATTRIBUTE(x) 0
8888
#endif
8989

90+
#if FMT_HAS_INCLUDE(<iterator>)
91+
# include <iterator>
92+
#endif
93+
9094
#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \
9195
(FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute))
9296

@@ -588,7 +592,21 @@ template <typename T> class basic_appender;
588592
using appender = basic_appender<char>;
589593

590594
// Checks whether T is a container with contiguous storage.
595+
#if FMT_HAS_INCLUDE(<iterator>)
596+
template <typename T, typename = void>
597+
struct is_contiguous : std::false_type {};
598+
599+
template <typename T>
600+
struct is_contiguous<
601+
T,
602+
void_t<decltype(std::data(std::declval<T&>())),
603+
decltype(std::declval<T&>().size()),
604+
decltype(std::declval<T&>().resize(size_t{})),
605+
decltype(std::declval<T&>()[size_t{}])>>
606+
: std::true_type {};
607+
#else
591608
template <typename T> struct is_contiguous : std::false_type {};
609+
#endif
592610

593611
class context;
594612
template <typename OutputIt, typename Char> class generic_context;

0 commit comments

Comments
 (0)