forked from boostorg/optional
fixed optional<optional<T>&> case
This commit is contained in:
@ -96,6 +96,7 @@ public:
|
||||
template <class U>
|
||||
explicit optional(const optional<U&>& rhs) BOOST_NOEXCEPT : ptr_(rhs.ptr_) {}
|
||||
optional(const optional& rhs) BOOST_NOEXCEPT : ptr_(rhs.ptr_) {}
|
||||
optional(T& rhs) BOOST_NOEXCEPT : ptr_(boost::addressof(rhs)) {}
|
||||
|
||||
|
||||
optional& operator=(const optional& rhs) BOOST_NOEXCEPT { ptr_ = rhs.ptr_; return *this; }
|
||||
@ -121,6 +122,8 @@ public:
|
||||
|
||||
#ifndef BOOST_OPTIONAL_DETAIL_NO_RVALUE_REFERENCES
|
||||
|
||||
optional(T&& rhs) BOOST_NOEXCEPT { detail::prevent_binding_rvalue<T&&>(); }
|
||||
|
||||
template <class R>
|
||||
optional(R&& r, BOOST_DEDUCED_TYPENAME boost::enable_if<detail::is_no_optional<R> >::type* = 0) BOOST_NOEXCEPT
|
||||
: ptr_(boost::addressof(r)) { detail::prevent_binding_rvalue<R>(); }
|
||||
|
@ -20,6 +20,7 @@ import testing ;
|
||||
[ run optional_test.cpp ]
|
||||
[ run optional_test_swap.cpp ]
|
||||
[ run optional_test_conversions_from_U.cpp ]
|
||||
[ run optional_test_convert_from_T.cpp ]
|
||||
[ run optional_test_tie.cpp ]
|
||||
[ run optional_test_ref_assign_portable_minimum.cpp ]
|
||||
[ run optional_test_ref_assign_mutable_int.cpp ]
|
||||
|
44
test/optional_test_convert_from_T.cpp
Normal file
44
test/optional_test_convert_from_T.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2014 Andrzej Krzemienski.
|
||||
//
|
||||
// Use, modification, and distribution is subject to the Boost Software
|
||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// See http://www.boost.org/lib/optional for documentation.
|
||||
//
|
||||
// You are welcome to contact the author at:
|
||||
// akrzemi1@gmail.com
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include "boost/core/lightweight_test.hpp"
|
||||
#include "boost/none.hpp"
|
||||
|
||||
//#ifndef BOOST_OPTIONAL_NO_CONVERTING_COPY_CTOR
|
||||
|
||||
using boost::optional;
|
||||
using boost::none;
|
||||
|
||||
void test_optional_optional_T()
|
||||
{
|
||||
optional<int> oi1 (1), oiN;
|
||||
optional< optional<int> > ooi1 (oi1), ooiN(oiN);
|
||||
|
||||
BOOST_TEST(ooi1);
|
||||
BOOST_TEST(*ooi1);
|
||||
BOOST_TEST_EQ(**ooi1, 1);
|
||||
|
||||
BOOST_TEST(ooiN);
|
||||
BOOST_TEST(!*ooiN);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_optional_optional_T();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -39,6 +39,7 @@ int main()
|
||||
{
|
||||
test_optional_ref_assignment<ScopeGuard>();
|
||||
test_optional_ref_assignment<Abstract>();
|
||||
test_optional_ref_assignment< optional<int> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -102,6 +102,7 @@ int main()
|
||||
test_all_const_cases<int>();
|
||||
test_all_const_cases<ScopeGuard>();
|
||||
test_all_const_cases<Abstract>();
|
||||
test_all_const_cases< optional<int> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -465,10 +465,12 @@ int main()
|
||||
test_optional_ref<int>();
|
||||
test_optional_ref<ScopeGuard>();
|
||||
test_optional_ref<Abstract>();
|
||||
test_optional_ref< optional<int> >();
|
||||
|
||||
test_optional_const_ref<int>();
|
||||
test_optional_const_ref<ScopeGuard>();
|
||||
test_optional_const_ref<Abstract>();
|
||||
test_optional_const_ref< optional<int> >();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
@ -12,6 +12,8 @@
|
||||
#ifndef BOOST_OPTIONAL_TEST_TESTABKE_CLASSES_AK_07JAN2015_HPP
|
||||
#define BOOST_OPTIONAL_TEST_TESTABKE_CLASSES_AK_07JAN2015_HPP
|
||||
|
||||
#include "boost/optional/optional.hpp"
|
||||
|
||||
struct ScopeGuard // no copy/move ctor/assign
|
||||
{
|
||||
int val_;
|
||||
@ -74,13 +76,23 @@ struct has_arrow<int>
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct has_arrow< boost::optional<int> >
|
||||
{
|
||||
static const bool value = false;
|
||||
};
|
||||
|
||||
int& val(int& i) { return i; }
|
||||
int& val(Abstract& a) { return a.val(); }
|
||||
int& val(Impl& a) { return a.val(); }
|
||||
int& val(ScopeGuard& g) { return g.val(); }
|
||||
template <typename T> int& val(T& o) { return *o; }
|
||||
|
||||
const int& val(const int& i) { return i; }
|
||||
const int& val(const Abstract& a) { return a.val(); }
|
||||
const int& val(const Impl& a) { return a.val(); }
|
||||
const int& val(const ScopeGuard& g) { return g.val(); }
|
||||
template <typename T> const int& val(const T& o) { return *o; }
|
||||
|
||||
bool operator==(const Abstract& l, const Abstract& r) { return l.val() == r.val(); }
|
||||
bool operator==(const ScopeGuard& l, const ScopeGuard& r) { return l.val() == r.val(); }
|
||||
|
Reference in New Issue
Block a user