* [PATCH] Define std::filesystem::path::format enum (P0430R2)
@ 2017-10-27 12:18 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2017-10-27 12:18 UTC (permalink / raw)
To: libstdc++, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 520 bytes --]
This enum doesn't do anything for POSIX systems, so this is a pretty
uninteresting change.
* 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.
Tested powerpc64le-linux, committed to trunk.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6051 bytes --]
commit 94acf4d0cfca501eab1387d544ffbf1ccba3e323
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Oct 27 12:47:35 2017 +0100
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.
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<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 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
+// <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();
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2017-10-27 12:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-27 12:18 [PATCH] Define std::filesystem::path::format enum (P0430R2) Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).