aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2017-10-27 13:01:49 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2017-10-27 13:01:49 +0100
commit0348dd008a1cba97328011ea2ac93691522a558f (patch)
treee453bf34346834a8780cb54ab9df22fd8ca63c14 /libstdc++-v3
parent57e7db041f0eb98fae437ab2519eeac06dbb5999 (diff)
downloadgcc-0348dd008a1cba97328011ea2ac93691522a558f.zip
gcc-0348dd008a1cba97328011ea2ac93691522a558f.tar.gz
gcc-0348dd008a1cba97328011ea2ac93691522a558f.tar.bz2
Define std::filesystem::path::format enum (P0430R2)
* include/bits/fs_path.h (path::format): Define new enumeration type. (path(string_type&&), path<Source>(const Source&)) (path<InputIterator>(InputIterator, InputIterator)) (path<Source>(const Source&, const locale&)) (path<InputIterator>(InputIterator, InputIterator, const locale&)): Add format parameter. * testsuite/27_io/filesystem/path/construct/format.cc: New test. From-SVN: r254144
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/bits/fs_path.h13
-rw-r--r--libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc116
3 files changed, 132 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index c53e12b..ea6b509 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,13 @@
2017-10-27 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/fs_path.h (path::format): Define new enumeration type.
+ (path(string_type&&), path<Source>(const Source&))
+ (path<InputIterator>(InputIterator, InputIterator))
+ (path<Source>(const Source&, const locale&))
+ (path<InputIterator>(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 6ba2bd2..7d97cdf 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<value_type> 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<typename _Source,
typename _Require = _Path<_Source>>
- 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<typename _InputIterator,
typename _Require = _Path<_InputIterator, _InputIterator>>
- path(_InputIterator __first, _InputIterator __last)
+ path(_InputIterator __first, _InputIterator __last, format = auto_format)
: _M_pathname(_S_convert(__first, __last))
{ _M_split_cmpts(); }
template<typename _Source,
typename _Require = _Path<_Source>,
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 _InputIterator,
typename _Require = _Path<_InputIterator, _InputIterator>,
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 0000000..e7ed19c
--- /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
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++17 -lstdc++fs" }
+// { dg-do run { target c++17 } }
+// { dg-require-filesystem-ts "" }
+
+#include <filesystem>
+#include <testsuite_hooks.h>
+
+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();
+}