Define std::filesystem::path::format enum (P0430R2)
authorJonathan Wakely <jwakely@redhat.com>
Fri, 27 Oct 2017 12:01:49 +0000 (13:01 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 27 Oct 2017 12:01:49 +0000 (13:01 +0100)
* 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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/fs_path.h
libstdc++-v3/testsuite/27_io/filesystem/path/construct/format.cc [new file with mode: 0644]

index c53e12b..ea6b509 100644 (file)
@@ -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.
index 6ba2bd2..7d97cdf 100644 (file)
@@ -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 (file)
index 0000000..e7ed19c
--- /dev/null
@@ -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();
+}