From 0348dd008a1cba97328011ea2ac93691522a558f Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Fri, 27 Oct 2017 13:01:49 +0100 Subject: [PATCH] Define std::filesystem::path::format enum (P0430R2) * include/bits/fs_path.h (path::format): Define new enumeration type. (path(string_type&&), path(const Source&)) (path(InputIterator, InputIterator)) (path(const Source&, const locale&)) (path(InputIterator, InputIterator, const locale&)): Add format parameter. * testsuite/27_io/filesystem/path/construct/format.cc: New test. From-SVN: r254144 --- libstdc++-v3/ChangeLog | 8 ++ libstdc++-v3/include/bits/fs_path.h | 13 +- .../27_io/filesystem/path/construct/format.cc | 116 ++++++++++++++++++ 3 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c53e12b7c37..ea6b509577e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,13 @@ 2017-10-27 Jonathan Wakely + * include/bits/fs_path.h (path::format): Define new enumeration type. + (path(string_type&&), path(const Source&)) + (path(InputIterator, InputIterator)) + (path(const Source&, const locale&)) + (path(InputIterator, InputIterator, const locale&)): + Add format parameter. + * testsuite/27_io/filesystem/path/construct/format.cc: New test. + * include/bits/stl_algo.h (__find_if_not_n, generate_n): Cast to void to ensure overloaded comma not used. * include/bits/stl_algobase.h (__fill_n_a, equal): Likewise. diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 6ba2bd2d43a..7d97cdfbb81 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -156,6 +156,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 #endif typedef std::basic_string string_type; + enum format { native_format, generic_format, auto_format }; + // constructors and destructor path() noexcept { } @@ -169,27 +171,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 __p.clear(); } - path(string_type&& __source) + path(string_type&& __source, format = auto_format) : _M_pathname(std::move(__source)) { _M_split_cmpts(); } template> - path(_Source const& __source) + path(_Source const& __source, format = auto_format) : _M_pathname(_S_convert(_S_range_begin(__source), _S_range_end(__source))) { _M_split_cmpts(); } template> - path(_InputIterator __first, _InputIterator __last) + path(_InputIterator __first, _InputIterator __last, format = auto_format) : _M_pathname(_S_convert(__first, __last)) { _M_split_cmpts(); } template, typename _Require2 = __value_type_is_char<_Source>> - path(_Source const& __source, const locale& __loc) + path(_Source const& __source, const locale& __loc, format = auto_format) : _M_pathname(_S_convert_loc(_S_range_begin(__source), _S_range_end(__source), __loc)) { _M_split_cmpts(); } @@ -197,7 +199,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 template, typename _Require2 = __value_type_is_char<_InputIterator>> - path(_InputIterator __first, _InputIterator __last, const locale& __loc) + path(_InputIterator __first, _InputIterator __last, const locale& __loc, + format = auto_format) : _M_pathname(_S_convert_loc(__first, __last, __loc)) { _M_split_cmpts(); } diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc new file mode 100644 index 00000000000..e7ed19cafe9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc @@ -0,0 +1,116 @@ +// Copyright (C) 2017 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-options "-std=gnu++17 -lstdc++fs" } +// { dg-do run { target c++17 } } +// { dg-require-filesystem-ts "" } + +#include +#include + +using std::filesystem::path; + +void +test01() +{ + auto s = [&]() -> path::string_type { return "foo/bar"; }; + path p0(s()); + path p1(s(), path::auto_format); + VERIFY( p1 == p0 ); + path p2(s(), path::native_format); + VERIFY( p2 == p0 ); + path p3(s(), path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test02() +{ + path::string_type s = "foo/bar"; + path p0(s); + path p1(s, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test03() +{ + const char* s = "foo/bar"; + path p0(s); + path p1(s, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test04() +{ + const char s[] = "foo/bar"; + path p0(std::begin(s), std::end(s)); + path p1(std::begin(s), std::end(s), path::auto_format); + VERIFY( p1 == p0 ); + path p2(std::begin(s), std::end(s), path::native_format); + VERIFY( p2 == p0 ); + path p3(std::begin(s), std::end(s), path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test05() +{ + const char* s = "foo/bar"; + std::locale loc; + path p0(s, loc); + path p1(s, loc, path::auto_format); + VERIFY( p1 == p0 ); + path p2(s, loc, path::native_format); + VERIFY( p2 == p0 ); + path p3(s, loc, path::generic_format); + VERIFY( p3 == p0 ); +} + +void +test06() +{ + const char s[] = "foo/bar"; + std::locale loc; + path p0(std::begin(s), std::end(s), loc); + path p1(std::begin(s), std::end(s), loc, path::auto_format); + VERIFY( p1 == p0 ); + path p2(std::begin(s), std::end(s), loc, path::native_format); + VERIFY( p2 == p0 ); + path p3(std::begin(s), std::end(s), loc, path::generic_format); + VERIFY( p3 == p0 ); +} + +int +main() +{ + test01(); + test02(); + test03(); + test04(); + test05(); + test06(); +} -- 2.30.2