summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2017-06-07 15:43:54 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2017-06-07 15:43:54 +0000
commit4bb28e46497f0819f5e3c4264cab7bbbd712b757 (patch)
treea594a0868225358bcc6ff9f4604556ca49b1696b /libstdc++-v3
parent478a417bada5bf762659e94cdc8bebac8e7ecc52 (diff)
downloadgcc-4bb28e46497f0819f5e3c4264cab7bbbd712b757.tar.gz
Add C++17 deduction guide for std::basic_regex (P0433R2, partial)
* include/bits/regex.h (basic_regex): Add deduction guide from P0433. * testsuite/28_regex/basic_regex/ctors/deduction.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248990 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog3
-rw-r--r--libstdc++-v3/include/bits/regex.h7
-rw-r--r--libstdc++-v3/testsuite/28_regex/basic_regex/ctors/deduction.cc61
3 files changed, 71 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index d7d6979da6f..a53c1ece09a 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,8 @@
2017-06-07 Jonathan Wakely <jwakely@redhat.com>
+ * include/bits/regex.h (basic_regex): Add deduction guide from P0433.
+ * testsuite/28_regex/basic_regex/ctors/deduction.cc: New.
+
PR libstdc++/81002
* include/bits/regex.h (basic_regex): Adjust call to __compile_nfa
so iterator type is deduced.
diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h
index 1710db90e74..0bb88cb6afb 100644
--- a/libstdc++-v3/include/bits/regex.h
+++ b/libstdc++-v3/include/bits/regex.h
@@ -787,6 +787,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_AutomatonPtr _M_automaton;
};
+#if __cpp_deduction_guides >= 201606
+ template<typename _ForwardIterator>
+ basic_regex(_ForwardIterator, _ForwardIterator,
+ regex_constants::syntax_option_type = {})
+ -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
+#endif
+
/** @brief Standard regular expressions. */
typedef basic_regex<char> regex;
diff --git a/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/deduction.cc b/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/deduction.cc
new file mode 100644
index 00000000000..63b3f67f5c9
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/basic_regex/ctors/deduction.cc
@@ -0,0 +1,61 @@
+// 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" }
+// { dg-do compile { target c++1z } }
+
+#include <regex>
+#include <testsuite_iterators.h>
+
+template<typename T, typename U> struct require_same;
+template<typename T> struct require_same<T, T> { using type = void; };
+
+template<typename T, typename U>
+ typename require_same<T, U>::type
+ check_type(U&) { }
+
+void
+test01()
+{
+ std::basic_regex x("");
+ check_type<std::basic_regex<char>>(x);
+ char s[1] = {};
+ std::basic_regex x2(s);
+ check_type<std::basic_regex<char>>(x2);
+ std::basic_regex x3(U"");
+ check_type<std::basic_regex<char32_t>>(x3);
+ std::basic_regex x4(U"", std::regex_constants::grep);
+ check_type<std::basic_regex<char32_t>>(x4);
+
+ // Test explicit guide:
+ std::basic_regex x5(s, s+1);
+ check_type<std::basic_regex<char>>(x5);
+ std::basic_regex x6((const char*)s, (const char*)s+1);
+ check_type<std::basic_regex<char>>(x6);
+ std::basic_regex x7(s, s+1, std::regex_constants::grep);
+ check_type<std::basic_regex<char>>(x7);
+ __gnu_test::test_container<char, __gnu_test::forward_iterator_wrapper> f(s);
+ std::basic_regex x8(f.begin(), f.end());
+ check_type<std::basic_regex<char>>(x8);
+ std::basic_regex x9(f.begin(), f.end(), std::regex_constants::grep);
+ check_type<std::basic_regex<char>>(x9);
+
+ std::basic_regex copy = x;
+ check_type<std::basic_regex<char>>(copy);
+ std::basic_regex move = std::move(x);
+ check_type<std::basic_regex<char>>(move);
+}