diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2018-05-23 01:57:02 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2018-05-23 01:57:02 +0000 |
commit | edd5e29cfe9f67ec8e7e0eda12eb05e616fdeebc (patch) | |
tree | 0659acce9ed1a364a771e7bb6b0d2a5fa00e232a /libcxx/test | |
parent | cab0d23ff77cbb35e85915e8ce4e4fdaa9eca486 (diff) | |
download | bcm5719-llvm-edd5e29cfe9f67ec8e7e0eda12eb05e616fdeebc.tar.gz bcm5719-llvm-edd5e29cfe9f67ec8e7e0eda12eb05e616fdeebc.zip |
Implement deduction guides for basic_regex
llvm-svn: 333050
Diffstat (limited to 'libcxx/test')
-rw-r--r-- | libcxx/test/std/re/re.regex/re.regex.construct/deduct.fail.cpp | 45 | ||||
-rw-r--r-- | libcxx/test/std/re/re.regex/re.regex.construct/deduct.pass.cpp | 137 |
2 files changed, 182 insertions, 0 deletions
diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/deduct.fail.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/deduct.fail.cpp new file mode 100644 index 00000000000..c4d60a5a95a --- /dev/null +++ b/libcxx/test/std/re/re.regex/re.regex.construct/deduct.fail.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + + +// template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>> +// vector(InputIterator, InputIterator, Allocator = Allocator()) +// -> vector<typename iterator_traits<InputIterator>::value_type, Allocator>; +// + + +#include <regex> +#include <string> +#include <iterator> +#include <cassert> +#include <cstddef> + + +int main() +{ +// Test the explicit deduction guides + { +// basic_regex(ForwardIterator, ForwardIterator) +// <int> is not an iterator + std::basic_regex re(23, 34); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_regex'}} + } + + { +// basic_regex(ForwardIterator, ForwardIterator, flag_type) +// <double> is not an iterator + std::basic_regex re(23.0, 34.0, std::regex_constants::basic); // expected-error {{no viable constructor or deduction guide for deduction of template arguments of 'basic_regex'}} + } + +// Test the implicit deduction guides + +} diff --git a/libcxx/test/std/re/re.regex/re.regex.construct/deduct.pass.cpp b/libcxx/test/std/re/re.regex/re.regex.construct/deduct.pass.cpp new file mode 100644 index 00000000000..5dbd2f11708 --- /dev/null +++ b/libcxx/test/std/re/re.regex/re.regex.construct/deduct.pass.cpp @@ -0,0 +1,137 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <regex> +// UNSUPPORTED: c++98, c++03, c++11, c++14 +// UNSUPPORTED: libcpp-no-deduction-guides + + +// template<class ForwardIterator> +// basic_regex(ForwardIterator, ForwardIterator, +// regex_constants::syntax_option_type = regex_constants::ECMAScript) +// -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; + + +#include <regex> +#include <string> +#include <iterator> +#include <cassert> +#include <cstddef> + +#include "test_macros.h" +#include "test_iterators.h" +#include "test_allocator.h" + +using namespace std::literals; + +struct A {}; + +int main() +{ + +// Test the explicit deduction guides + { +// basic_regex(ForwardIterator, ForwardIterator) + std::string s1("\\(a\\)"); + std::basic_regex re(s1.begin(), s1.end()); + + static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); + assert(re.flags() == std::regex_constants::ECMAScript); + assert(re.mark_count() == 0); + } + + { + std::wstring s1(L"\\(a\\)"); + std::basic_regex re(s1.begin(), s1.end(), std::regex_constants::basic); + + static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); + assert(re.flags() == std::regex_constants::basic); + assert(re.mark_count() == 1); + } + +// Test the implicit deduction guides + { +// basic_regex(string); + std::basic_regex re("(a([bc]))"s); + static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); + assert(re.flags() == std::regex_constants::ECMAScript); + assert(re.mark_count() == 2); + } + + { +// basic_regex(string, flag_type); + std::basic_regex re(L"(a([bc]))"s, std::regex_constants::awk); + static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); + assert(re.flags() == std::regex_constants::awk); + assert(re.mark_count() == 2); + } + + { +// basic_regex(const charT*); + std::basic_regex re("ABCDE"); + static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); + assert(re.flags() == std::regex_constants::ECMAScript); + assert(re.mark_count() == 0); + } + + { +// basic_regex(const charT*, flag_type); + std::basic_regex re(L"ABCDE", std::regex_constants::grep); + static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); + assert(re.flags() == std::regex_constants::grep); + assert(re.mark_count() == 0); + } + + { +// basic_regex(const charT*, size_t); + std::basic_regex re("ABCDEDEF", 7); + static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); + assert(re.flags() == std::regex_constants::ECMAScript); + assert(re.mark_count() == 0); + } + + { +// basic_regex(const charT*, size_t, flag_type); + std::basic_regex re(L"ABCDEDEF", 8, std::regex_constants::awk); + static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); + assert(re.flags() == std::regex_constants::awk); + assert(re.mark_count() == 0); + } + + { +// basic_regex(const basic_regex &); + std::basic_regex<char> source; + std::basic_regex re(source); + static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); + assert(re.flags() == source.flags()); + assert(re.mark_count() == source.mark_count()); + } + + { +// template<class ST, class SA> +// explicit basic_regex(const basic_string<charT, ST, SA>& p, +// flag_type f = regex_constants::ECMAScript); + } + + { +// basic_regex(initializer_list); + std::basic_regex re({'A', 'B', 'F', 'E', 'D'}); + static_assert(std::is_same_v<decltype(re), std::basic_regex<char>>, ""); + assert(re.flags() == std::regex_constants::ECMAScript); + assert(re.mark_count() == 0); + } + + { +// basic_regex(initializer_list, flag_type); + std::basic_regex re({L'A', L'B', L'F', L'E', L'D'}, std::regex_constants::grep); + static_assert(std::is_same_v<decltype(re), std::basic_regex<wchar_t>>, ""); + assert(re.flags() == std::regex_constants::grep); + assert(re.mark_count() == 0); + } +} |