summaryrefslogtreecommitdiff
path: root/libstdc++-v3/include
diff options
context:
space:
mode:
authorbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-24 16:33:14 +0000
committerbkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-24 16:33:14 +0000
commit31f8cfa67473cb14a45c17089d5932b40c35b71c (patch)
treefa31f22e39362968b11b217d2c9f0e344384479d /libstdc++-v3/include
parent366a26da65204a36e5e43e35e1b1b9b9c7a8ed33 (diff)
downloadgcc-31f8cfa67473cb14a45c17089d5932b40c35b71c.tar.gz
2010-11-24 Benjamin Kosnik <bkoz@redhat.com>
* include/std/tuple: Mark more constructors constexpr. * include/bits/stl_pair.h: Same. * testsuite/20_util/tuple/requirements/dr801.cc: New. * testsuite/20_util/pair/requirements/dr801.cc: New. * testsuite/20_util/tuple/cons/constexpr.cc: Add cases for new constexpr constructors. * testsuite/20_util/pair/cons/constexpr.cc: Same. * testsuite/20_util/pair/comparison_operators/constexpr.cc: New. * testsuite/20_util/weak_ptr/comparison/cmp_neg.cc: Adjust line number. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@167118 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r--libstdc++-v3/include/bits/stl_pair.h109
-rw-r--r--libstdc++-v3/include/std/tuple27
2 files changed, 71 insertions, 65 deletions
diff --git a/libstdc++-v3/include/bits/stl_pair.h b/libstdc++-v3/include/bits/stl_pair.h
index 0e651e7ba76..c6753f6d5d9 100644
--- a/libstdc++-v3/include/bits/stl_pair.h
+++ b/libstdc++-v3/include/bits/stl_pair.h
@@ -98,63 +98,67 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: first(), second() { }
/** Two objects may be passed to a @c pair constructor to be copied. */
- pair(const _T1& __a, const _T2& __b)
+ _GLIBCXX_CONSTEXPR pair(const _T1& __a, const _T2& __b)
: first(__a), second(__b) { }
+ /** There is also a templated copy ctor for the @c pair class itself. */
+ template<class _U1, class _U2>
+ _GLIBCXX_CONSTEXPR pair(const pair<_U1, _U2>& __p)
+ : first(__p.first), second(__p.second) { }
+
#ifdef __GXX_EXPERIMENTAL_CXX0X__
- pair(const pair&) = default;
+ constexpr pair(const pair&) = default;
+
+ // Implicit.
+ // pair(pair&&) = default;
// DR 811.
template<class _U1, class = typename
std::enable_if<std::is_convertible<_U1, _T1>::value>::type>
- pair(_U1&& __x, const _T2& __y)
- : first(std::forward<_U1>(__x)),
- second(__y) { }
+ pair(_U1&& __x, const _T2& __y)
+ : first(std::forward<_U1>(__x)), second(__y) { }
template<class _U2, class = typename
std::enable_if<std::is_convertible<_U2, _T2>::value>::type>
- pair(const _T1& __x, _U2&& __y)
- : first(__x),
- second(std::forward<_U2>(__y)) { }
+ pair(const _T1& __x, _U2&& __y)
+ : first(__x), second(std::forward<_U2>(__y)) { }
template<class _U1, class _U2, class = typename
std::enable_if<std::is_convertible<_U1, _T1>::value
&& std::is_convertible<_U2, _T2>::value>::type>
- pair(_U1&& __x, _U2&& __y)
- : first(std::forward<_U1>(__x)),
- second(std::forward<_U2>(__y)) { }
+ pair(_U1&& __x, _U2&& __y)
+ : first(std::forward<_U1>(__x)), second(std::forward<_U2>(__y)) { }
- template<class... _Args1, class... _Args2>
- pair(piecewise_construct_t,
- tuple<_Args1...> __first_args,
- tuple<_Args2...> __second_args)
- : first(__cons<first_type>(std::move(__first_args))),
- second(__cons<second_type>(std::move(__second_args))) { }
-#endif
-
- /** There is also a templated copy ctor for the @c pair class itself. */
template<class _U1, class _U2>
- pair(const pair<_U1, _U2>& __p)
- : first(__p.first),
- second(__p.second) { }
-
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
- template<class _U1, class _U2>
- pair(pair<_U1, _U2>&& __p)
+ pair(pair<_U1, _U2>&& __p)
: first(std::forward<_U1>(__p.first)),
second(std::forward<_U2>(__p.second)) { }
+ template<class... _Args1, class... _Args2>
+ pair(piecewise_construct_t,
+ tuple<_Args1...> __first, tuple<_Args2...> __second)
+ : first(__cons<first_type>(std::move(__first))),
+ second(__cons<second_type>(std::move(__second))) { }
+
+ pair&
+ operator=(const pair& __p)
+ {
+ first = __p.first;
+ second = __p.second;
+ return *this;
+ }
+
pair&
operator=(pair&& __p)
- {
+ {
first = std::move(__p.first);
second = std::move(__p.second);
return *this;
}
template<class _U1, class _U2>
- pair&
- operator=(const pair<_U1, _U2>& __p)
+ pair&
+ operator=(const pair<_U1, _U2>& __p)
{
first = __p.first;
second = __p.second;
@@ -162,8 +166,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
}
template<class _U1, class _U2>
- pair&
- operator=(pair<_U1, _U2>&& __p)
+ pair&
+ operator=(pair<_U1, _U2>&& __p)
{
first = std::move(__p.first);
second = std::move(__p.second);
@@ -175,54 +179,54 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
{
using std::swap;
swap(first, __p.first);
- swap(second, __p.second);
+ swap(second, __p.second);
}
private:
template<typename _Tp, typename... _Args>
- static _Tp
- __cons(tuple<_Args...>&&);
+ static _Tp
+ __cons(tuple<_Args...>&&);
template<typename _Tp, typename... _Args, int... _Indexes>
- static _Tp
- __do_cons(tuple<_Args...>&&, const _Index_tuple<_Indexes...>&);
+ static _Tp
+ __do_cons(tuple<_Args...>&&, const _Index_tuple<_Indexes...>&);
#endif
};
/// Two pairs of the same type are equal iff their members are equal.
template<class _T1, class _T2>
- inline bool
+ inline _GLIBCXX_CONSTEXPR bool
operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{ return __x.first == __y.first && __x.second == __y.second; }
/// <http://gcc.gnu.org/onlinedocs/libstdc++/manual/utilities.html>
template<class _T1, class _T2>
- inline bool
+ inline _GLIBCXX_CONSTEXPR bool
operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{ return __x.first < __y.first
|| (!(__y.first < __x.first) && __x.second < __y.second); }
/// Uses @c operator== to find the result.
template<class _T1, class _T2>
- inline bool
+ inline _GLIBCXX_CONSTEXPR bool
operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{ return !(__x == __y); }
/// Uses @c operator< to find the result.
template<class _T1, class _T2>
- inline bool
+ inline _GLIBCXX_CONSTEXPR bool
operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{ return __y < __x; }
/// Uses @c operator< to find the result.
template<class _T1, class _T2>
- inline bool
+ inline _GLIBCXX_CONSTEXPR bool
operator<=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{ return !(__y < __x); }
/// Uses @c operator< to find the result.
template<class _T1, class _T2>
- inline bool
+ inline _GLIBCXX_CONSTEXPR bool
operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
{ return !(__x < __y); }
@@ -248,22 +252,23 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
*/
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 181. make_pair() unintended behavior
-#ifndef __GXX_EXPERIMENTAL_CXX0X__
- template<class _T1, class _T2>
- inline pair<_T1, _T2>
- make_pair(_T1 __x, _T2 __y)
- { return pair<_T1, _T2>(__x, __y); }
-#else
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
// NB: DR 706.
template<class _T1, class _T2>
inline pair<typename __decay_and_strip<_T1>::__type,
typename __decay_and_strip<_T2>::__type>
make_pair(_T1&& __x, _T2&& __y)
{
- return pair<typename __decay_and_strip<_T1>::__type,
- typename __decay_and_strip<_T2>::__type>
- (std::forward<_T1>(__x), std::forward<_T2>(__y));
+ typedef typename __decay_and_strip<_T1>::__type __ds_type1;
+ typedef typename __decay_and_strip<_T2>::__type __ds_type2;
+ typedef pair<__ds_type1, __ds_type2> __pair_type;
+ return __pair_type(std::forward<_T1>(__x), std::forward<_T2>(__y));
}
+#else
+ template<class _T1, class _T2>
+ inline pair<_T1, _T2>
+ make_pair(_T1 __x, _T2 __y)
+ { return pair<_T1, _T2>(__x, __y); }
#endif
_GLIBCXX_END_NAMESPACE
diff --git a/libstdc++-v3/include/std/tuple b/libstdc++-v3/include/std/tuple
index 682712104a2..df9ef1d1694 100644
--- a/libstdc++-v3/include/std/tuple
+++ b/libstdc++-v3/include/std/tuple
@@ -67,7 +67,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
constexpr _Head_base()
: _Head() { }
- _Head_base(const _Head& __h)
+ constexpr _Head_base(const _Head& __h)
: _Head(__h) { }
template<typename _UHead>
@@ -77,7 +77,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_Head& _M_head() { return *this; }
const _Head& _M_head() const { return *this; }
- void _M_swap_impl(_Head&) { /* no-op */ }
+ void
+ _M_swap_impl(_Head&) { /* no-op */ }
};
template<std::size_t _Idx, typename _Head>
@@ -86,7 +87,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
constexpr _Head_base()
: _M_head_impl() { }
- _Head_base(const _Head& __h)
+ constexpr _Head_base(const _Head& __h)
: _M_head_impl(__h) { }
template<typename _UHead>
@@ -151,7 +152,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _Inherited(), _Base() { }
explicit
- _Tuple_impl(const _Head& __head, const _Tail&... __tail)
+ constexpr _Tuple_impl(const _Head& __head, const _Tail&... __tail)
: _Inherited(__tail...), _Base(__head) { }
template<typename _UHead, typename... _UTail>
@@ -160,10 +161,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _Inherited(std::forward<_UTail>(__tail)...),
_Base(std::forward<_UHead>(__head)) { }
- _Tuple_impl(const _Tuple_impl&) = default;
+ constexpr _Tuple_impl(const _Tuple_impl&) = default;
_Tuple_impl(_Tuple_impl&& __in)
- : _Inherited(std::move(__in._M_tail())),
+ : _Inherited(std::move(__in._M_tail())),
_Base(std::forward<_Head>(__in._M_head())) { }
template<typename... _UElements>
@@ -229,7 +230,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _Inherited() { }
explicit
- tuple(const _Elements&... __elements)
+ constexpr tuple(const _Elements&... __elements)
: _Inherited(__elements...) { }
template<typename... _UElements, typename = typename
@@ -239,7 +240,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
tuple(_UElements&&... __elements)
: _Inherited(std::forward<_UElements>(__elements)...) { }
- tuple(const tuple&) = default;
+ constexpr tuple(const tuple&) = default;
tuple(tuple&& __in)
: _Inherited(static_cast<_Inherited&&>(__in)) { }
@@ -314,7 +315,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _Inherited() { }
explicit
- tuple(const _T1& __a1, const _T2& __a2)
+ constexpr tuple(const _T1& __a1, const _T2& __a2)
: _Inherited(__a1, __a2) { }
template<typename _U1, typename _U2>
@@ -322,7 +323,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
tuple(_U1&& __a1, _U2&& __a2)
: _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { }
- tuple(const tuple&) = default;
+ constexpr tuple(const tuple&) = default;
tuple(tuple&& __in)
: _Inherited(static_cast<_Inherited&&>(__in)) { }
@@ -412,7 +413,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
: _Inherited() { }
explicit
- tuple(const _T1& __a1)
+ constexpr tuple(const _T1& __a1)
: _Inherited(__a1) { }
template<typename _U1, typename = typename
@@ -421,14 +422,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
tuple(_U1&& __a1)
: _Inherited(std::forward<_U1>(__a1)) { }
- tuple(const tuple&) = default;
+ constexpr tuple(const tuple&) = default;
tuple(tuple&& __in)
: _Inherited(static_cast<_Inherited&&>(__in)) { }
template<typename _U1>
tuple(const tuple<_U1>& __in)
- : _Inherited(static_cast<const _Tuple_impl<0, _U1>&>(__in)) { }
+ : _Inherited(static_cast<const _Tuple_impl<0, _U1>&>(__in)) { }
template<typename _U1>
tuple(tuple<_U1>&& __in)