Index: include/experimental/__config =================================================================== --- include/experimental/__config +++ include/experimental/__config @@ -25,6 +25,10 @@ #define _LIBCPP_END_NAMESPACE_LFTS } } } #define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1 +#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 { +#define _LIBCPP_END_NAMESPACE_LFTS_V2 } } } +#define _VSTD_LFTS_V2 _VSTD_EXPERIMENTAL::fundamentals_v2 + #define _LIBCPP_BEGIN_NAMESPACE_CHRONO_LFTS _LIBCPP_BEGIN_NAMESPACE_STD \ namespace chrono { namespace experimental { inline namespace fundamentals_v1 { #define _LIBCPP_END_NAMESPACE_CHRONO_LFTS _LIBCPP_END_NAMESPACE_STD } } } Index: include/experimental/propagate_const =================================================================== --- /dev/null +++ include/experimental/propagate_const @@ -0,0 +1,559 @@ +// -*- C++ -*- +//===------------------------ propagate_const -----------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST +#define _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST + +/* + propagate_const synopsis + + namespace std { namespace experimental { inline namespace fundamentals_v2 { + + // [propagate_const] + template class propagate_const; + + // [propagate_const.underlying], underlying pointer access + constexpr const _Tp& get_underlying(const propagate_const& pt) noexcept; + constexpr T& get_underlying(__propagate_const& pt) noexcept; + + // [propagate_const.relational], relational operators + template constexpr bool operator==(const propagate_const& pt, nullptr_t); + template constexpr bool operator==(nullptr_t, const propagate_const& pu); + template constexpr bool operator!=(const propagate_const& pt, nullptr_t); + template constexpr bool operator!=(nullptr_t, const propagate_const& pu); + template constexpr bool operator==(const propagate_const& pt, const propagate_const<_Up>& pu); + template constexpr bool operator!=(const propagate_const& pt, const propagate_const<_Up>& pu); + template constexpr bool operator<(const propagate_const& pt, const propagate_const<_Up>& pu); + template constexpr bool operator>(const propagate_const& pt, const propagate_const<_Up>& pu); + template constexpr bool operator<=(const propagate_const& pt, const propagate_const<_Up>& pu); + template constexpr bool operator>=(const propagate_const& pt, const propagate_const<_Up>& pu); + template constexpr bool operator==(const propagate_const& pt, const _Up& u); + template constexpr bool operator!=(const propagate_const& pt, const _Up& u); + template constexpr bool operator<(const propagate_const& pt, const _Up& u); + template constexpr bool operator>(const propagate_const& pt, const _Up& u); + template constexpr bool operator<=(const propagate_const& pt, const _Up& u); + template constexpr bool operator>=(const propagate_const& pt, const _Up& u); + template constexpr bool operator==(const _Tp& t, const propagate_const<_Up>& pu); + template constexpr bool operator!=(const _Tp& t, const propagate_const<_Up>& pu); + template constexpr bool operator<(const _Tp& t, const propagate_const<_Up>& pu); + template constexpr bool operator>(const _Tp& t, const propagate_const<_Up>& pu); + template constexpr bool operator<=(const _Tp& t, const propagate_const<_Up>& pu); + template constexpr bool operator>=(const _Tp& t, const propagate_const<_Up>& pu); + + // [propagate_const.algorithms], specialized algorithms + template constexpr void swap(propagate_const& pt, propagate_const& pu) noexcept(see below); + + template + class propagate_const + { + + public: + typedef remove_reference_t())> element_type; + + // [propagate_const.ctor], constructors + constexpr propagate_const() = default; + propagate_const(const propagate_const& p) = delete; + constexpr propagate_const(propagate_const&& p) = default; + template EXPLICIT constexpr propagate_const(propagate_const<_Up>&& pu); // see below + template EXPLICIT constexpr propagate_const(U&& u); // see below + + // [propagate_const.assignment], assignment + propagate_const& operator=(const propagate_const& p) = delete; + constexpr propagate_const& operator=(propagate_const&& p) = default; + template constexpr propagate_const& operator=(propagate_const<_Up>&& pu); + template constexpr propagate_const& operator=(U&& u); // see below + + // [propagate_const.const_observers], const observers + explicit constexpr operator bool() const; + constexpr const element_type* operator->() const; + constexpr operator const element_type*() const; // Not always defined + constexpr const element_type& operator*() const; + constexpr const element_type* get() const; + + // [propagate_const.non_const_observers], non-const observers + constexpr element_type* operator->(); + constexpr operator element_type*(); // Not always defined + constexpr element_type& operator*(); + constexpr element_type* get(); + + // [propagate_const.modifiers], modifiers + constexpr void swap(propagate_const& pt) noexcept(see below) + + private: + T t_; // exposition only + }; + + } // namespace fundamentals_v2 + } // namespace experimental + + // [propagate_const.hash], hash support + template struct hash>; + + // [propagate_const.comparison_function_objects], comparison function objects + template struct equal_to>; + template struct not_equal_to>; + template struct less>; + template struct greater>; + template struct less_equal>; + template struct greater_equal>; + +} // namespace std + +*/ + +#include + +#if _LIBCPP_STD_VER > 11 + +#include +#include +#include + +_LIBCPP_BEGIN_NAMESPACE_LFTS_V2 + +template +class propagate_const +{ + +public: + typedef remove_reference_t())> element_type; + +private: + template + static element_type* __get_pointer(_Up* __u) + { + return __u; + } + + template + static element_type* __get_pointer(_Up& __u) + { + return __get_pointer(__u.get()); + } + + template + static const element_type* __get_pointer(const _Up* __u) + { + return __u; + } + + template + static const element_type* __get_pointer(const _Up& __u) + { + return __get_pointer(__u.get()); + } + + template + struct is_propagate_const : false_type + { + }; + + template + struct is_propagate_const> : true_type + { + }; + + _Tp __t_; + +public: + + template friend _LIBCPP_CONSTEXPR const _Up& get_underlying(const propagate_const<_Up>& __pu) _NOEXCEPT; + template friend _LIBCPP_CONSTEXPR _Up& get_underlying(propagate_const<_Up>& __pu) _NOEXCEPT; + + _LIBCPP_CONSTEXPR propagate_const() _LIBCPP_DEFAULT + + propagate_const(const propagate_const&) = delete; + + _LIBCPP_CONSTEXPR propagate_const(propagate_const&&) _LIBCPP_DEFAULT + + template ::value && + is_constructible<_Tp, _Up&&>::value,bool> = true> + explicit _LIBCPP_CONSTEXPR propagate_const(propagate_const<_Up>&& __pu) + : __t_(std::move(get_underlying(__pu))) + { + } + + template ::value && + is_constructible<_Tp, _Up&&>::value,bool> = false> + _LIBCPP_CONSTEXPR propagate_const(propagate_const<_Up>&& __pu) + : __t_(std::move(get_underlying(__pu))) + { + } + + template ::value && + is_constructible<_Tp, _Up&&>::value && + !is_propagate_const>::value,bool> = true> + explicit _LIBCPP_CONSTEXPR propagate_const(_Up&& __u) + : __t_(std::forward<_Up>(__u)) + { + } + + template ::value && + is_constructible<_Tp, _Up&&>::value && + !is_propagate_const>::value,bool> = false> + _LIBCPP_CONSTEXPR propagate_const(_Up&& __u) + : __t_(std::forward<_Up>(__u)) + { + } + + propagate_const& operator=(const propagate_const&) = delete; + + _LIBCPP_CONSTEXPR propagate_const& operator=(propagate_const&&) _LIBCPP_DEFAULT + + template + _LIBCPP_CONSTEXPR propagate_const& operator=(propagate_const<_Up>&& __pu) + { + __t_ = std::move(get_underlying(__pu)); + return *this; + } + + template >::value>> + _LIBCPP_CONSTEXPR propagate_const& operator=(_Up&& __u) + { + __t_ = std::forward<_Up>(__u); + return *this; + } + + _LIBCPP_CONSTEXPR const element_type* get() const + { + return __get_pointer(__t_); + } + + _LIBCPP_CONSTEXPR element_type* get() + { + return __get_pointer(__t_); + } + + explicit _LIBCPP_CONSTEXPR operator bool() const + { + return get() != nullptr; + } + + _LIBCPP_CONSTEXPR const element_type* operator->() const + { + return get(); + } + + template ::value>> + operator const element_type *() const { + return get(); + } + + _LIBCPP_CONSTEXPR const element_type& operator*() const + { + return *get(); + } + + _LIBCPP_CONSTEXPR element_type* operator->() + { + return get(); + } + + template ::value>> + operator element_type *() { + return get(); + } + + _LIBCPP_CONSTEXPR element_type& operator*() + { + return *get(); + } + + _LIBCPP_CONSTEXPR void swap(propagate_const& __pt) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) + { + _VSTD::swap(__t_, __pt.__t_); + } +}; + + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const propagate_const<_Tp>& __pt, nullptr_t) +{ + return get_underlying(__pt) == nullptr; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(nullptr_t, const propagate_const<_Tp>& __pt) +{ + return nullptr == get_underlying(__pt); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const propagate_const<_Tp>& __pt, nullptr_t) +{ + return get_underlying(__pt) != nullptr; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(nullptr_t, const propagate_const<_Tp>& __pt) +{ + return nullptr != get_underlying(__pt); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return get_underlying(__pt) == get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return get_underlying(__pt) != get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return get_underlying(__pt) < get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return get_underlying(__pt) > get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return get_underlying(__pt) <= get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) +{ + return get_underlying(__pt) >= get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return get_underlying(__pt) == __u; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return get_underlying(__pt) != __u; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return get_underlying(__pt) < __u; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return get_underlying(__pt) > __u; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<=(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return get_underlying(__pt) <= __u; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>=(const propagate_const<_Tp>& __pt, const _Up& __u) +{ + return get_underlying(__pt) >= __u; +} + + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator==(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t == get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator!=(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t != get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t < get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t > get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator<=(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t <= get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR bool operator>=(const _Tp& __t, const propagate_const<_Up>& __pu) +{ + return __t >= get_underlying(__pu); +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR void swap(propagate_const<_Tp>& __pc1, propagate_const<_Tp>& __pc2) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) +{ + _VSTD::swap(get_underlying(__pc1), get_underlying(__pc2)); +} + + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR const _Tp& get_underlying(const propagate_const<_Tp>& __pt) _NOEXCEPT +{ + return __pt.__t_; +} + +template +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR _Tp& get_underlying(propagate_const<_Tp>& __pt) _NOEXCEPT +{ + return __pt.__t_; +} + +_LIBCPP_END_NAMESPACE_LFTS_V2 + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct hash> +{ + typedef size_t result_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> argument_type; + + size_t operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1) const + { + return std::hash<_Tp>()(get_underlying(__pc1)); + } +}; + +template +struct equal_to> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::equal_to<_Tp>()(get_underlying(__pc1), get_underlying(__pc2)); + } +}; + +template +struct not_equal_to> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::not_equal_to<_Tp>()(get_underlying(__pc1), get_underlying(__pc2)); + } +}; + +template +struct less> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::less<_Tp>()(get_underlying(__pc1), get_underlying(__pc2)); + } +}; + +template +struct greater> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::greater<_Tp>()(get_underlying(__pc1), get_underlying(__pc2)); + } +}; + +template +struct less_equal> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::less_equal<_Tp>()(get_underlying(__pc1), get_underlying(__pc2)); + } +}; + +template +struct greater_equal> +{ + typedef experimental::fundamentals_v2::propagate_const<_Tp> first_argument_type; + typedef experimental::fundamentals_v2::propagate_const<_Tp> second_argument_type; + + bool operator()(const experimental::fundamentals_v2::propagate_const<_Tp>& __pc1, + const experimental::fundamentals_v2::propagate_const<_Tp>& __pc2) const + { + return std::greater_equal<_Tp>()(get_underlying(__pc1), get_underlying(__pc2)); + } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_STD_VER > 11 +#endif // _LIBCPP_EXPERIMENTAL_PROPAGATE_CONST + Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template propagate_const& propagate_const::operator=(const propagate_const&)=delete; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p1(1); + P p2(2); + + p2=p1; // will not compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign_convertible_element_type.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign_convertible_element_type.pass.cpp @@ -0,0 +1,34 @@ + +// +// 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, c++11 + +// + +// template propagate_const& propagate_const::operator=(U&&); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const PY; + + X x1(1); + PY p(2); + + assert(*p==2); + + p = x1; + + assert(*p==1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign_convertible_propagate_const.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign_convertible_propagate_const.fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr propagate_const& operator=(U&& u); // won't bind to propagate_const + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const PX; + typedef propagate_const PY; + + PX px2(2); + PY py1(1); + + py1=px2; // won't compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign_element_type.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/assign_element_type.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template propagate_const& propagate_const::operator=(U&&); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + X x1(1); + P p(2); + + assert(*p==2); + + p = x1; + + assert(*p==1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/move_assign.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/move_assign.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template propagate_const& propagate_const::operator=(propagate_const&&); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p1(1); + P p2(2); + + p2=std::move(p1); + + assert(*p2==1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/move_assign_convertible.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/move_assign_convertible.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template propagate_const& propagate_const::operator=(propagate_const&&); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const PX; + typedef propagate_const PY; + + PX px2(2); + PY py1(1); + + py1=std::move(px2); + + assert(*py1==2); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/move_assign_convertible_propagate_const.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.assignment/move_assign_convertible_propagate_const.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr propagate_const& operator=(propagate_const<_Up>&& pu); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const PX; + typedef propagate_const PY; + + PX px2(2); + PY py1(1); + + py1=std::move(px2); + + assert(*py1==2); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_element_type.explicit.ctor.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_element_type.explicit.ctor.fail.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr propagate_const& operator=(propagate_const<_Up>&& pu); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +typedef propagate_const P; + +void f(const P& p) +{ +} + +int main() { + f(X(2)); // will not compile +} + Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_element_type.non-explicit.ctor.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_element_type.non-explicit.ctor.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr propagate_const& operator=(propagate_const<_Up>&& pu); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +typedef propagate_const P; + +void f(const P& p) +{ + assert(*p==2); +} + +int main() { + f(X(2)); +} + Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_propagate_const.copy_ctor.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_propagate_const.copy_ctor.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr propagate_const& operator(propagate_const<_Up>&& pu); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +typedef propagate_const PY; +typedef propagate_const PX; + +int main() { + PX px(1); + PY py(px); // will not compile +} + Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_propagate_const.explicit.move_ctor.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_propagate_const.explicit.move_ctor.fail.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr propagate_const(propagate_const<_Up>&& pu); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +typedef propagate_const PY; +typedef propagate_const PX; + +void f(const PY&) +{ +} + +int main() { + PX px(1); + f(std::move(px)); // will not compile +} + Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_propagate_const.move_ctor.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/convertible_propagate_const.move_ctor.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr propagate_const& operator(propagate_const<_Up>&& pu); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +typedef propagate_const PY; +typedef propagate_const PX; + +int main() { + PX px(1); + PY py(std::move(px)); + + assert(*py==1); +} + Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/copy_ctor.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/copy_ctor.fail.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// propagate_const(const propagate_const&)=delete; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p1(2); + P p2(p1); // will not compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/element_type.explicit.ctor.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/element_type.explicit.ctor.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template propagate_const(U&&); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +typedef propagate_const P; + +void f(const P&) +{ +} + +int main() { + f(2); // will not compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/element_type.non-explicit.ctor.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/element_type.non-explicit.ctor.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template propagate_const(U&&); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +typedef propagate_const P; + +void f(const P&) +{ +} + +int main() { + f(2); // will not compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/move_ctor.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.ctors/move_ctor.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// propagate_const(propagate_const&&)=default; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p1(2); + P p2(std::move(p1)); // will not compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/dereference.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/dereference.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// element_type& propagate_const::operator*(); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + *p = 2; + assert(*p==2); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/get.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/get.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// element_type* propagate_const::get(); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + *p.get() = 2; + + assert(*(p.get())==2); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/op_arrow.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/op_arrow.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// element_type* propagate_const::operator->(); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + *(p.operator->()) = 2; + + assert(*(p.operator->())==2); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/operator_element_type_ptr.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/operator_element_type_ptr.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// propagate_const::operator element_type*(); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + int* ptr_1 = p; // will not compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/operator_element_type_ptr.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.non-const_observers/operator_element_type_ptr.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// propagate_const::operator element_type*(); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + int* ptr_1 = p; + + assert(*ptr_1==1); + + *ptr_1 = 2; + + assert(*ptr_1==2); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/dereference.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/dereference.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// const element_type& propagate_const::operator*() const; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + assert(*p==1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/get.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/get.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// const element_type* propagate_const::get() const; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + assert(*(p.get())==1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/op_arrow.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/op_arrow.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// const element_type* propagate_const::operator->() const; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + assert(*(p.operator->())==1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/operator_element_type_ptr.fail.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/operator_element_type_ptr.fail.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// propagate_const::operator const element_type*() const; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + const int* ptr_1 = p; // will not compile +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/operator_element_type_ptr.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/propagate_const.observers/operator_element_type_ptr.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// propagate_const::operator const element_type*() const; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +int main() { + + typedef propagate_const P; + + P p(1); + + const int* ptr_1 = p; + + assert(*ptr_1==1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.class/swap.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.class/swap.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr void propagate_const::swap(propagate_const& x); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +void swap(X& x, X& y) +{ + std::swap(x.i_,y.i_); +} + +int main() { + typedef propagate_const P; + + P p1_1(1); + P p2_2(2); + + assert(*p1_1 == 1); + assert(*p2_2 == 2); + + p1_1.swap(p2_2); + + assert(*p1_1 == 2); + assert(*p2_2 == 1); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/hash.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/hash.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template struct hash>; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +namespace std { +template <> struct hash +{ + typedef X first_argument_type; + + size_t operator()(const first_argument_type& x1) const + { + return 99; + } + +}; +} // namespace std + +int main() { + + typedef propagate_const P; + + P p(1); + + auto h = std::hash

(); + + assert(h(p)==99); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/equal_to.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/equal_to.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template struct equal_to>; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +namespace std { +template <> struct equal_to +{ + typedef X first_argument_type; + typedef X second_argument_type; + + constexpr bool operator()(const first_argument_type& x1, const second_argument_type& x2) const + { + return equal_to()(x1.i_,x2.i_); + } +}; +} // namespace std + +int main() { + + typedef propagate_const P; + + P p1_1(1); + P p2_1(1); + P p3_2(2); + + auto c = std::equal_to

(); + + assert(c(p1_1,p2_1)); + assert(!c(p1_1,p3_2)); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/greater.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/greater.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template struct greater>; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +namespace std { +template <> struct greater +{ + typedef X first_argument_type; + typedef X second_argument_type; + + constexpr bool operator()(const first_argument_type& x1, const second_argument_type& x2) const + { + return greater()(x1.i_,x2.i_); + } +}; +} // namespace std + +int main() { + + typedef propagate_const P; + + P p1_1(1); + P p2_1(1); + P p3_2(2); + + auto c = std::greater

(); + + assert(!c(p1_1,p2_1)); + assert(!c(p2_1,p1_1)); + assert(!c(p1_1,p3_2)); + assert(c(p3_2,p1_1)); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/greater_equal.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/greater_equal.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template struct greater_equal>; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +namespace std { +template <> struct greater_equal +{ + typedef X first_argument_type; + typedef X second_argument_type; + + constexpr bool operator()(const first_argument_type& x1, const second_argument_type& x2) const + { + return greater_equal()(x1.i_,x2.i_); + } +}; +} // namespace std + +int main() { + + typedef propagate_const P; + + P p1_1(1); + P p2_1(1); + P p3_2(2); + + auto c = std::greater_equal

(); + + assert(c(p1_1,p2_1)); + assert(c(p2_1,p1_1)); + assert(!c(p1_1,p3_2)); + assert(c(p3_2,p1_1)); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/less.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/less.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template struct less>; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +namespace std { +template <> struct less +{ + typedef X first_argument_type; + typedef X second_argument_type; + + constexpr bool operator()(const first_argument_type& x1, const second_argument_type& x2) const + { + return less()(x1.i_,x2.i_); + } +}; +} // namespace std + +int main() { + + typedef propagate_const P; + + P p1_1(1); + P p2_1(1); + P p3_2(2); + + auto c = std::less

(); + + assert(!c(p1_1,p2_1)); + assert(!c(p2_1,p1_1)); + assert(c(p1_1,p3_2)); + assert(!c(p3_2,p1_1)); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/less_equal.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/less_equal.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template struct less_equal>; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +namespace std { +template <> struct less_equal +{ + typedef X first_argument_type; + typedef X second_argument_type; + + constexpr bool operator()(const first_argument_type& x1, const second_argument_type& x2) const + { + return less_equal()(x1.i_,x2.i_); + } +}; +} // namespace std + +int main() { + + typedef propagate_const P; + + P p1_1(1); + P p2_1(1); + P p3_2(2); + + auto c = std::less_equal

(); + + assert(c(p1_1,p2_1)); + assert(c(p2_1,p1_1)); + assert(c(p1_1,p3_2)); + assert(!c(p3_2,p1_1)); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/not_equal_to.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.comparison_function_objects/not_equal_to.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template struct not_equal_to>; + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +namespace std { +template <> struct not_equal_to +{ + typedef X first_argument_type; + typedef X second_argument_type; + + constexpr bool operator()(const first_argument_type& x1, const second_argument_type& x2) const + { + return not_equal_to()(x1.i_,x2.i_); + } +}; +} // namespace std + +int main() { + + typedef propagate_const P; + + P p1_1(1); + P p2_1(1); + P p3_2(2); + + auto c = std::not_equal_to

(); + + assert(!c(p1_1,p2_1)); + assert(c(p1_1,p3_2)); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/equal.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/equal.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr bool operator==(const propagate_const& x, const propagate_const& y); +// template constexpr bool operator==(const T& x, const propagate_const& y); +// template constexpr bool operator==(const propagate_const& x, const T& y); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; +using std::nullptr_t; + +constexpr bool operator==(const X &lhs, const X &rhs) { + return lhs.i_ == rhs.i_; +} + +constexpr bool operator==(const X &, const nullptr_t &) { + return false; +} + +constexpr bool operator==(const nullptr_t &, const X &) { + return false; +} + +int main() { + constexpr X x1_1(1); + constexpr X x2_1(1); + constexpr X x3_2(2); + + static_assert(x1_1 == x1_1, ""); + static_assert(x1_1 == x2_1, ""); + static_assert(!(x1_1 == x3_2), ""); + + typedef propagate_const P; + + constexpr P p1_1(1); + constexpr P p2_1(1); + constexpr P p3_2(2); + + static_assert(p1_1 == p1_1, ""); + static_assert(p1_1 == p2_1, ""); + static_assert(!(p1_1 == p3_2), ""); + + static_assert(x1_1 == p1_1, ""); + static_assert(!(x1_1 == p3_2), ""); + + static_assert(p1_1 == x1_1, ""); + static_assert(!(p1_1 == x3_2), ""); + + static_assert(!(p1_1==nullptr),""); + static_assert(!(nullptr==p1_1),""); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/greater_equal.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/greater_equal.pass.cpp @@ -0,0 +1,54 @@ +//>==---------------------------------------------------------------------->==// +// +// 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, c++11 + +// + +// template constexpr bool operator>=(const propagate_const& x, const propagate_const& y); +// template constexpr bool operator>=(const T& x, const propagate_const& y); +// template constexpr bool operator>=(const propagate_const& x, const T& y); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +constexpr bool operator>=(const X &lhs, const X &rhs) { + return lhs.i_ >= rhs.i_; +} + +int main() { + constexpr X x1_1(1); + constexpr X x2_1(1); + constexpr X x3_2(2); + + static_assert(x1_1 >= x2_1, ""); + static_assert(!(x1_1 >= x3_2), ""); + static_assert(x3_2 >= x1_1, ""); + + typedef propagate_const P; + + constexpr P p1_1(1); + constexpr P p2_1(1); + constexpr P p3_2(2); + + static_assert(p1_1 >= p2_1, ""); + static_assert(!(p1_1 >= p3_2), ""); + static_assert(p3_2 >= p1_1, ""); + + static_assert(p1_1 >= x2_1, ""); + static_assert(!(p1_1 >= x3_2), ""); + static_assert(p3_2 >= x1_1, ""); + + static_assert(x1_1 >= p2_1, ""); + static_assert(!(x1_1 >= p3_2), ""); + static_assert(x3_2 >= p1_1, ""); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/greater_than.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/greater_than.pass.cpp @@ -0,0 +1,50 @@ +//>=---------------------------------------------------------------------->=// +// +// 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, c++11 + +// + +// template constexpr bool operator>(const propagate_const& x, const propagate_const& y); +// template constexpr bool operator>(const T& x, const propagate_const& y); +// template constexpr bool operator>(const propagate_const& x, const T& y); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +constexpr bool operator>(const X &lhs, const X &rhs) { + return lhs.i_ > rhs.i_; +} + +int main() { + constexpr X x1_1(1); + constexpr X x2_1(1); + constexpr X x3_2(2); + + static_assert(!(x1_1 > x2_1), ""); + static_assert(x3_2 > x1_1, ""); + + typedef propagate_const P; + + constexpr P p1_1(1); + constexpr P p2_1(1); + constexpr P p3_2(2); + + static_assert(!(p1_1 > p2_1), ""); + static_assert(p3_2 > p1_1, ""); + + static_assert(!(p1_1 > x2_1), ""); + static_assert(p3_2 > x1_1, ""); + + static_assert(!(x1_1 > p2_1), ""); + static_assert(x3_2 > p1_1, ""); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/less_equal.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/less_equal.pass.cpp @@ -0,0 +1,55 @@ +//<==----------------------------------------------------------------------<==// +// +// 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, c++11 + +// + +// template constexpr bool operator<=(const propagate_const& x, const propagate_const& y); +// template constexpr bool operator<=(const T& x, const propagate_const& y); +// template constexpr bool operator<=(const propagate_const& x, const T& y); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +constexpr bool operator<=(const X &lhs, const X &rhs) { + return lhs.i_ <= rhs.i_; +} + +int main() { + constexpr X x1_1(1); + constexpr X x2_1(1); + constexpr X x3_2(2); + + static_assert(x1_1 <= x2_1, ""); + static_assert(x1_1 <= x3_2, ""); + static_assert(!(x3_2 <= x1_1), ""); + + typedef propagate_const P; + + constexpr P p1_1(1); + constexpr P p2_1(1); + constexpr P p3_2(2); + + static_assert(p1_1 <= p2_1, ""); + static_assert(p1_1 <= p3_2, ""); + static_assert(!(p3_2 <= p1_1), ""); + + static_assert(p1_1 <= x2_1, ""); + static_assert(p1_1 <= x3_2, ""); + static_assert(!(p3_2 <= x1_1), ""); + + static_assert(x1_1 <= p2_1, ""); + static_assert(x1_1 <= p3_2, ""); + static_assert(!(x3_2 <= p1_1), ""); + +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/less_than.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/less_than.pass.cpp @@ -0,0 +1,50 @@ +//<=----------------------------------------------------------------------<=// +// +// 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, c++11 + +// + +// template constexpr bool operator<(const propagate_const& x, const propagate_const& y); +// template constexpr bool operator<(const T& x, const propagate_const& y); +// template constexpr bool operator<(const propagate_const& x, const T& y); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +constexpr bool operator<(const X &lhs, const X &rhs) { + return lhs.i_ < rhs.i_; +} + +int main() { + constexpr X x1_1(1); + constexpr X x2_1(1); + constexpr X x3_2(2); + + static_assert(!(x1_1 < x2_1), ""); + static_assert(x1_1 < x3_2, ""); + + typedef propagate_const P; + + constexpr P p1_1(1); + constexpr P p2_1(1); + constexpr P p3_2(2); + + static_assert(!(p1_1 < p2_1), ""); + static_assert(p1_1 < p3_2, ""); + + static_assert(!(x1_1 < p1_1), ""); + static_assert(x1_1 < p3_2, ""); + + static_assert(!(p1_1 < x1_1), ""); + static_assert(p1_1 < x3_2, ""); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/not_equal.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/propagate_const.relops/not_equal.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr bool operator!=(const propagate_const& x, const propagate_const& y); +// template constexpr bool operator!=(const T& x, const propagate_const& y); +// template constexpr bool operator!=(const propagate_const& x, const T& y); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; +using std::nullptr_t; + +constexpr bool operator!=(const X &lhs, const X &rhs) { + return lhs.i_ != rhs.i_; +} + +constexpr bool operator!=(const X &, const nullptr_t &) { + return true; +} + +constexpr bool operator!=(const nullptr_t &, const X &) { + return true; +} + +int main() { + constexpr X x1_1(1); + constexpr X x2_1(1); + constexpr X x3_2(2); + + static_assert(!(x1_1 != x2_1), ""); + static_assert(x1_1 != x3_2, ""); + + typedef propagate_const P; + + constexpr P p1_1(1); + constexpr P p2_1(1); + constexpr P p3_2(2); + + static_assert(!(p1_1 != p2_1), ""); + static_assert(p1_1 != p3_2, ""); + + static_assert(!(x1_1 != p1_1), ""); + static_assert(x1_1 != p3_2, ""); + + static_assert(!(p1_1 != x1_1), ""); + static_assert(p1_1 != x3_2, ""); + + static_assert(p1_1!=nullptr,""); + static_assert(nullptr!=p1_1,""); +} Index: test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/swap.pass.cpp =================================================================== --- /dev/null +++ test/std/experimental/utilities/propagate_const/propagate_const.nonmembers/swap.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// 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, c++11 + +// + +// template constexpr void swap(propagate_const& x, propagate_const& y); + +#include +#include "propagate_const_helpers.h" +#include + +using std::experimental::propagate_const; + +void swap(X& x, X& y) +{ + std::swap(x.i_,y.i_); +} + +int main() { + typedef propagate_const P; + + P p1_1(1); + P p2_2(2); + + assert(*p1_1 == 1); + assert(*p2_2 == 2); + + swap(p1_1, p2_2); + + assert(*p1_1 == 2); + assert(*p2_2 == 1); +} Index: test/support/propagate_const_helpers.h =================================================================== --- /dev/null +++ test/support/propagate_const_helpers.h @@ -0,0 +1,119 @@ + // A lightweight class, with pointer-like methods, that contains an int +struct X +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + + constexpr X(int i) : i_(i) {} +}; + +struct XWithImplicitIntStarConversion +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + operator int* () { return &i_; } + + constexpr XWithImplicitIntStarConversion(int i) : i_(i) {} +}; + +struct XWithImplicitConstIntStarConversion +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + operator int* () { return &i_; } + + constexpr XWithImplicitConstIntStarConversion(int i) : i_(i) {} +}; + +struct ExplicitX +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + + constexpr explicit ExplicitX(int i) : i_(i) {} +}; + +struct MoveConstructibleFromX +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + + constexpr MoveConstructibleFromX(int i) : i_(i) {} + constexpr MoveConstructibleFromX(X&& x) : i_(x.i_) {} +}; + +struct ExplicitMoveConstructibleFromX +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + + constexpr ExplicitMoveConstructibleFromX(int i) : i_(i) {} + constexpr explicit ExplicitMoveConstructibleFromX(X&& x) : i_(x.i_) {} +}; + +struct CopyConstructibleFromX +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + + constexpr CopyConstructibleFromX(int i) : i_(i) {} + constexpr CopyConstructibleFromX(const X& x) : i_(x.i_) {} +}; + +struct ExplicitCopyConstructibleFromX +{ + int i_; + + const int &operator*() const { return i_; } + int &operator*() { return i_; } + const int *get() const { return &i_; } + int *get() { return &i_; } + const int *operator->() const { return &i_; } + int *operator->() { return &i_; } + + constexpr ExplicitCopyConstructibleFromX(int i) : i_(i) {} + constexpr explicit ExplicitCopyConstructibleFromX(const X& x) : i_(x.i_) {} +}; +