diff options
author | Eric Fiselier <eric@efcs.ca> | 2016-05-07 03:09:55 +0000 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2016-05-07 03:09:55 +0000 |
commit | 522a7f953522bf8c133bc51b305f52c29c5d6595 (patch) | |
tree | 2ab560bed00c2af8259d6373d21c97b4d0cfaedb /libcxx/test/std/experimental/memory | |
parent | 4b30c797239ffd5135f2285831b09a58567188e0 (diff) | |
download | bcm5719-llvm-522a7f953522bf8c133bc51b305f52c29c5d6595.tar.gz bcm5719-llvm-522a7f953522bf8c133bc51b305f52c29c5d6595.zip |
Add experimental container alias templates for PMRs
llvm-svn: 268841
Diffstat (limited to 'libcxx/test/std/experimental/memory')
10 files changed, 576 insertions, 0 deletions
diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_deque_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_deque_synop.pass.cpp new file mode 100644 index 00000000000..b41fbf73307 --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_deque_synop.pass.cpp @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/deque> + +// namespace std { namespace experimental { namespace pmr { +// template <class T> +// using deque = +// ::std::deque<T, polymorphic_allocator<T>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/deque> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +int main() +{ + using StdDeque = std::deque<int, pmr::polymorphic_allocator<int>>; + using PmrDeque = pmr::deque<int>; + static_assert(std::is_same<StdDeque, PmrDeque>::value, ""); + PmrDeque d; + assert(d.get_allocator().resource() == pmr::get_default_resource()); +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_forward_list_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_forward_list_synop.pass.cpp new file mode 100644 index 00000000000..ab588b8efe6 --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_forward_list_synop.pass.cpp @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/forward_list> + +// namespace std { namespace experimental { namespace pmr { +// template <class T> +// using forward_list = +// ::std::forward_list<T, polymorphic_allocator<T>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/forward_list> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +int main() +{ + using StdForwardList = std::forward_list<int, pmr::polymorphic_allocator<int>>; + using PmrForwardList = pmr::forward_list<int>; + static_assert(std::is_same<StdForwardList, PmrForwardList>::value, ""); + PmrForwardList d; + assert(d.get_allocator().resource() == pmr::get_default_resource()); +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_list_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_list_synop.pass.cpp new file mode 100644 index 00000000000..9c2c91789ef --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_list_synop.pass.cpp @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/list> + +// namespace std { namespace experimental { namespace pmr { +// template <class T> +// using list = +// ::std::list<T, polymorphic_allocator<T>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/list> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +int main() +{ + using StdList = std::list<int, pmr::polymorphic_allocator<int>>; + using PmrList = pmr::list<int>; + static_assert(std::is_same<StdList, PmrList>::value, ""); + PmrList d; + assert(d.get_allocator().resource() == pmr::get_default_resource()); +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_map_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_map_synop.pass.cpp new file mode 100644 index 00000000000..37e9cf68c77 --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_map_synop.pass.cpp @@ -0,0 +1,68 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/map> + +// namespace std { namespace experimental { namespace pmr { +// template <class K, class V, class Compare = less<Key> > +// using map = +// ::std::map<K, V, Compare, polymorphic_allocator<pair<const K, V>>> +// +// template <class K, class V, class Compare = less<Key> > +// using multimap = +// ::std::multimap<K, V, Compare, polymorphic_allocator<pair<const K, V>>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/map> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +int main() +{ + using K = int; + using V = char; + using DC = std::less<int>; + using OC = std::greater<int>; + using P = std::pair<const K, V>; + { + using StdMap = std::map<K, V, DC, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::map<K, V>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + using StdMap = std::map<K, V, OC, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::map<K, V, OC>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + pmr::map<int, int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } + { + using StdMap = std::multimap<K, V, DC, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::multimap<K, V>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + using StdMap = std::multimap<K, V, OC, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::multimap<K, V, OC>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + pmr::multimap<int, int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_regex_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_regex_synop.pass.cpp new file mode 100644 index 00000000000..706a763993f --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_regex_synop.pass.cpp @@ -0,0 +1,56 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/regex> + +// namespace std { namespace experimental { namespace pmr { +// +// template <class BidirectionalIterator> +// using match_results = +// std::match_results<BidirectionalIterator, +// polymorphic_allocator<sub_match<BidirectionalIterator>>>; +// +// typedef match_results<const char*> cmatch; +// typedef match_results<const wchar_t*> wcmatch; +// typedef match_results<string::const_iterator> smatch; +// typedef match_results<wstring::const_iterator> wsmatch; +// +// }}} // namespace std::experimental::pmr + +#include <experimental/regex> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +template <class Iter, class PmrTypedef> +void test_match_result_typedef() { + using StdMR = std::match_results<Iter, pmr::polymorphic_allocator<std::sub_match<Iter>>>; + using PmrMR = pmr::match_results<Iter>; + static_assert(std::is_same<StdMR, PmrMR>::value, ""); + static_assert(std::is_same<PmrMR, PmrTypedef>::value, ""); +} + +int main() +{ + { + test_match_result_typedef<const char*, pmr::cmatch>(); + test_match_result_typedef<const wchar_t*, pmr::wcmatch>(); + test_match_result_typedef<pmr::string::const_iterator, pmr::smatch>(); + test_match_result_typedef<pmr::wstring::const_iterator, pmr::wsmatch>(); + } + { + // Check that std::match_results has been included and is complete. + pmr::smatch s; + assert(s.get_allocator().resource() == pmr::get_default_resource()); + } +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_set_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_set_synop.pass.cpp new file mode 100644 index 00000000000..6823006399e --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_set_synop.pass.cpp @@ -0,0 +1,66 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/set> + +// namespace std { namespace experimental { namespace pmr { +// template <class V, class Compare = less<V> > +// using set = +// ::std::set<V, Compare, polymorphic_allocator<V>> +// +// template <class V, class Compare = less<V> > +// using multiset = +// ::std::multiset<V, Compare, polymorphic_allocator<V>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/set> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +int main() +{ + using V = char; + using DC = std::less<V>; + using OC = std::greater<V>; + { + using StdSet = std::set<V, DC, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::set<V>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + using StdSet = std::set<V, OC, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::set<V, OC>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + pmr::set<int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } + { + using StdSet = std::multiset<V, DC, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::multiset<V>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + using StdSet = std::multiset<V, OC, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::multiset<V, OC>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + pmr::multiset<int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_string_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_string_synop.pass.cpp new file mode 100644 index 00000000000..c160a09e445 --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_string_synop.pass.cpp @@ -0,0 +1,72 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/string> + +// namespace std { namespace experimental { namespace pmr { +// template <class Char, class Traits = ...> +// using basic_string = +// ::std::basic_string<Char, Traits, polymorphic_allocator<Char>> +// +// typedef ... string +// typedef ... u16string +// typedef ... u32string +// typedef ... wstring +// +// }}} // namespace std::experimental::pmr + +#include <experimental/string> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +#include "constexpr_char_traits.hpp" + +namespace pmr = std::experimental::pmr; + +template <class Char, class PmrTypedef> +void test_string_typedef() { + using StdStr = std::basic_string<Char, std::char_traits<Char>, + pmr::polymorphic_allocator<Char>>; + using PmrStr = pmr::basic_string<Char>; + static_assert(std::is_same<StdStr, PmrStr>::value, ""); + static_assert(std::is_same<PmrStr, PmrTypedef>::value, ""); +} + +template <class Char, class Traits> +void test_basic_string_alias() { + using StdStr = std::basic_string<Char, Traits, + pmr::polymorphic_allocator<Char>>; + using PmrStr = pmr::basic_string<Char, Traits>; + static_assert(std::is_same<StdStr, PmrStr>::value, ""); +} + +int main() +{ + { + test_string_typedef<char, pmr::string>(); + test_string_typedef<wchar_t, pmr::wstring>(); + test_string_typedef<char16_t, pmr::u16string>(); + test_string_typedef<char32_t, pmr::u32string>(); + } + { + test_basic_string_alias<char, constexpr_char_traits<char>>(); + test_basic_string_alias<wchar_t, constexpr_char_traits<wchar_t>>(); + test_basic_string_alias<char16_t, constexpr_char_traits<char16_t>>(); + test_basic_string_alias<char32_t, constexpr_char_traits<char32_t>>(); + } + { + // Check that std::basic_string has been included and is complete. + pmr::string s; + assert(s.get_allocator().resource() == pmr::get_default_resource()); + } +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_unordered_map_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_unordered_map_synop.pass.cpp new file mode 100644 index 00000000000..77f44a9b840 --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_unordered_map_synop.pass.cpp @@ -0,0 +1,86 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/unordered_map> + +// namespace std { namespace experimental { namespace pmr { +// template <class K, class V, class H = hash<K>, class P = equal_to<K> > +// using unordered_map = +// ::std::unordered_map<K, V, H, P, polymorphic_allocator<pair<const K, V>>> +// +// template <class K, class V, class H = hash<K>, class P = equal_to<K> > +// using unordered_multimap = +// ::std::unordered_multimap<K, V, H, P, polymorphic_allocator<pair<const K, V>>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/unordered_map> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +template <class T> +struct MyHash : std::hash<T> {}; + +template <class T> +struct MyPred : std::equal_to<T> {}; + +int main() +{ + using K = int; + using V = char; + using DH = std::hash<K>; + using MH = MyHash<K>; + using DP = std::equal_to<K>; + using MP = MyPred<K>; + using P = std::pair<const K, V>; + { + using StdMap = std::unordered_map<K, V, DH, DP, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::unordered_map<K, V>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + using StdMap = std::unordered_map<K, V, MH, DP, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::unordered_map<K, V, MH>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + using StdMap = std::unordered_map<K, V, MH, MP, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::unordered_map<K, V, MH, MP>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + pmr::unordered_map<int, int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } + { + using StdMap = std::unordered_multimap<K, V, DH, DP, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::unordered_multimap<K, V>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + using StdMap = std::unordered_multimap<K, V, MH, DP, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::unordered_multimap<K, V, MH>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + using StdMap = std::unordered_multimap<K, V, MH, MP, pmr::polymorphic_allocator<P>>; + using PmrMap = pmr::unordered_multimap<K, V, MH, MP>; + static_assert(std::is_same<StdMap, PmrMap>::value, ""); + } + { + pmr::unordered_multimap<int, int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_unordered_set_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_unordered_set_synop.pass.cpp new file mode 100644 index 00000000000..214c7dca433 --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_unordered_set_synop.pass.cpp @@ -0,0 +1,84 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/unordered_set> + +// namespace std { namespace experimental { namespace pmr { +// template <class V, class H = hash<V>, class P = equal_to<V> > +// using unordered_set = +// ::std::unordered_set<V, H, P, polymorphic_allocator<V>> +// +// template <class V, class H = hash<V>, class P = equal_to<V> > +// using unordered_multiset = +// ::std::unordered_multiset<V, H, P, polymorphic_allocator<V>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/unordered_set> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +template <class T> +struct MyHash : std::hash<T> {}; + +template <class T> +struct MyPred : std::equal_to<T> {}; + +int main() +{ + using V = char; + using DH = std::hash<V>; + using MH = MyHash<V>; + using DP = std::equal_to<V>; + using MP = MyPred<V>; + { + using StdSet = std::unordered_set<V, DH, DP, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::unordered_set<V>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + using StdSet = std::unordered_set<V, MH, DP, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::unordered_set<V, MH>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + using StdSet = std::unordered_set<V, MH, MP, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::unordered_set<V, MH, MP>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + pmr::unordered_set<int, int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } + { + using StdSet = std::unordered_multiset<V, DH, DP, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::unordered_multiset<V>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + using StdSet = std::unordered_multiset<V, MH, DP, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::unordered_multiset<V, MH>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + using StdSet = std::unordered_multiset<V, MH, MP, pmr::polymorphic_allocator<V>>; + using PmrSet = pmr::unordered_multiset<V, MH, MP>; + static_assert(std::is_same<StdSet, PmrSet>::value, ""); + } + { + pmr::unordered_multiset<int, int> m; + assert(m.get_allocator().resource() == pmr::get_default_resource()); + } +} diff --git a/libcxx/test/std/experimental/memory/memory.resource.aliases/header_vector_synop.pass.cpp b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_vector_synop.pass.cpp new file mode 100644 index 00000000000..814ade6d0c2 --- /dev/null +++ b/libcxx/test/std/experimental/memory/memory.resource.aliases/header_vector_synop.pass.cpp @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++98, c++03 + +// <experimental/vector> + +// namespace std { namespace experimental { namespace pmr { +// template <class T> +// using vector = +// ::std::vector<T, polymorphic_allocator<T>> +// +// }}} // namespace std::experimental::pmr + +#include <experimental/vector> +#include <experimental/memory_resource> +#include <type_traits> +#include <cassert> + +namespace pmr = std::experimental::pmr; + +int main() +{ + using StdVector = std::vector<int, pmr::polymorphic_allocator<int>>; + using PmrVector = pmr::vector<int>; + static_assert(std::is_same<StdVector, PmrVector>::value, ""); + PmrVector d; + assert(d.get_allocator().resource() == pmr::get_default_resource()); +} |