diff options
Diffstat (limited to 'test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp')
| -rw-r--r-- | test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp b/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp index 4c2d5112d10b..9e48cbf1e7f2 100644 --- a/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp +++ b/test/std/experimental/filesystem/class.path/path.member/path.assign/source.pass.cpp @@ -23,6 +23,7 @@ #include <experimental/filesystem> #include <type_traits> +#include <string_view> #include <cassert> #include "test_macros.h" @@ -69,6 +70,32 @@ void RunTestCase(MultiStringType const& MS) { assert(p.string<CharT>() == TestPath); assert(p.string<CharT>() == S); } + // basic_string<Char, Traits, Alloc> + { + const std::basic_string_view<CharT> S(TestPath); + path p; PathReserve(p, S.length() + 1); + { + // string provides a contigious iterator. No allocation needed. + DisableAllocationGuard g; + path& pref = (p = S); + assert(&pref == &p); + } + assert(p.native() == Expect); + assert(p.string<CharT>() == TestPath); + assert(p.string<CharT>() == S); + } + { + const std::basic_string_view<CharT> S(TestPath); + path p; PathReserve(p, S.length() + 1); + { + DisableAllocationGuard g; + path& pref = p.assign(S); + assert(&pref == &p); + } + assert(p.native() == Expect); + assert(p.string<CharT>() == TestPath); + assert(p.string<CharT>() == S); + } ////////////////////////////////////////////////////////////////////////////// // Char* pointers { @@ -143,6 +170,49 @@ void RunTestCase(MultiStringType const& MS) { } } +template <class It, class = decltype(fs::path{}.assign(std::declval<It>()))> +constexpr bool has_assign(int) { return true; } +template <class It> +constexpr bool has_assign(long) { return false; } +template <class It> +constexpr bool has_assign() { return has_assign<It>(0); } + +void test_sfinae() { + using namespace fs; + { + using It = const char* const; + static_assert(std::is_assignable<path, It>::value, ""); + static_assert(has_assign<It>(), ""); + } + { + using It = input_iterator<const char*>; + static_assert(std::is_assignable<path, It>::value, ""); + static_assert(has_assign<It>(), ""); + } + { + struct Traits { + using iterator_category = std::input_iterator_tag; + using value_type = const char; + using pointer = const char*; + using reference = const char&; + using difference_type = std::ptrdiff_t; + }; + using It = input_iterator<const char*, Traits>; + static_assert(std::is_assignable<path, It>::value, ""); + static_assert(has_assign<It>(), ""); + } + { + using It = output_iterator<const char*>; + static_assert(!std::is_assignable<path, It>::value, ""); + static_assert(!has_assign<It>(), ""); + + } + { + static_assert(!std::is_assignable<path, int*>::value, ""); + static_assert(!has_assign<int*>(), ""); + } +} + int main() { for (auto const& MS : PathList) { RunTestCase<char>(MS); @@ -150,4 +220,5 @@ int main() { RunTestCase<char16_t>(MS); RunTestCase<char32_t>(MS); } + test_sfinae(); } |
