diff --git a/doc/28_ref_optional_semantics.qbk b/doc/28_ref_optional_semantics.qbk index 07f7a43..6ccea46 100644 --- a/doc/28_ref_optional_semantics.qbk +++ b/doc/28_ref_optional_semantics.qbk @@ -621,8 +621,10 @@ __SPACE__ of type `T` with `std::forward(args)...`. * [*Postconditions: ] `*this` is [_initialized]. * [*Throws:] Whatever the selected `T`'s constructor throws. -* [*Notes:] `T` need not be __MOVE_CONSTRUCTIBLE__ or `MoveAssignable`. On compilers that do not support variadic templates, the signature falls back to single-argument: `template void emplace(Arg&& arg)`. On compilers that do not support rvalue references, the signature falls back to two overloads: taking `const` and non-`const` lvalue reference. * [*Exception Safety:] If an exception is thrown during the initialization of `T`, `*this` is ['uninitialized]. +* [*Notes:] `T` need not be __MOVE_CONSTRUCTIBLE__ or `MoveAssignable`. + On compilers that do not support variadic templates, the signature falls back to two overloads:`template void emplace(Arg&& arg)` and `void emplace()`. + On compilers that do not support rvalue references, the signature falls back to three overloads: taking `const` and non-`const` lvalue reference, and third with empty function argument list. * [*Example:] `` T v; diff --git a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html index a54a583..e2b974f 100644 --- a/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html +++ b/doc/html/boost_optional/reference/header__boost_optional_optional_hpp_/detailed_semantics.html @@ -1336,23 +1336,26 @@
  • Throws: Whatever the selected T's constructor throws.
  • -
  • - Notes: T - need not be MoveConstructible - or MoveAssignable. - On compilers that do not support variadic templates, the signature - falls back to single-argument: template<class - Arg> - void emplace(Arg&& arg). On compilers that do not support - rvalue references, the signature falls back to two overloads: taking - const and non-const lvalue reference. -
  • Exception Safety: If an exception is thrown during the initialization of T, *this is uninitialized.
  • +
  • + Notes: T + need not be MoveConstructible + or MoveAssignable. + On compilers that do not support variadic templates, the signature + falls back to two overloads:template<class + Arg> + void emplace(Arg&& arg) and void + emplace(). + On compilers that do not support rvalue references, the signature falls + back to three overloads: taking const + and non-const lvalue reference, + and third with empty function argument list. +
  • Example:
    T v;
    diff --git a/doc/html/index.html b/doc/html/index.html
    index 891941d..2a66e9d 100644
    --- a/doc/html/index.html
    +++ b/doc/html/index.html
    @@ -146,7 +146,7 @@
     
     
     
    -
    +

    Last revised: March 13, 2015 at 21:52:15 GMT

    Last revised: May 15, 2015 at 14:16:05 GMT


    diff --git a/include/boost/optional/optional.hpp b/include/boost/optional/optional.hpp index 64ddac8..fd7cf73 100644 --- a/include/boost/optional/optional.hpp +++ b/include/boost/optional/optional.hpp @@ -18,12 +18,14 @@ #define BOOST_OPTIONAL_OPTIONAL_FLC_19NOV2002_HPP #include -#include #include #include #include +#include +#include #include +#include #include #include #include @@ -47,13 +49,7 @@ #include #include #include -#include #include -#include -#include -#include - - #include @@ -506,6 +502,13 @@ class optional_base : public optional_tag ::new (m_storage.address()) internal_type( boost::forward(arg) ); m_initialized = true ; } + + void emplace_assign () + { + destroy(); + ::new (m_storage.address()) internal_type(); + m_initialized = true ; + } #else template void emplace_assign ( const Arg& arg ) @@ -515,13 +518,20 @@ class optional_base : public optional_tag m_initialized = true ; } - template + template void emplace_assign ( Arg& arg ) { destroy(); ::new (m_storage.address()) internal_type( arg ); m_initialized = true ; } + + void emplace_assign () + { + destroy(); + ::new (m_storage.address()) internal_type(); + m_initialized = true ; + } #endif #ifndef BOOST_OPTIONAL_NO_INPLACE_FACTORY_SUPPORT @@ -976,6 +986,11 @@ class optional : public optional_detail::optional_base { this->emplace_assign( boost::forward(arg) ); } + + void emplace () + { + this->emplace_assign(); + } #else template void emplace ( const Arg& arg ) @@ -988,6 +1003,11 @@ class optional : public optional_detail::optional_base { this->emplace_assign( arg ); } + + void emplace () + { + this->emplace_assign(); + } #endif void swap( optional & arg ) @@ -1448,9 +1468,9 @@ struct swap_selector return; if( !hasX ) - x = boost::in_place(); + x.emplace(); else if ( !hasY ) - y = boost::in_place(); + y.emplace(); // Boost.Utility.Swap will take care of ADL and workarounds for broken compilers boost::swap(x.get(),y.get()); diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d654545..ea9e81b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -1,15 +1,16 @@ -# Boost.Optional Library test Jamfile +# Boost.Optional Library test Jamfile # -# Copyright (C) 2003, Fernando Luis Cacciola Carballal. +# Copyright (C) 2003, Fernando Luis Cacciola Carballal. +# Copyright (C) 2014, 2015 Andrzej Krzemienski # -# This material is provided "as is", with absolutely no warranty expressed -# or implied. Any use is at your own risk. +# 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) # -# Permission to use or copy this software for any purpose is hereby granted -# without fee, provided the above notices are retained on all copies. -# Permission to modify the code and to distribute modified code is granted, -# provided the above notices are retained, and a notice that the code was -# modified is included with the above copyright notice. +# See http://www.boost.org/libs/optional for documentation. +# +# You are welcome to contact the author at: +# akrzemi1@gmail.com # import testing ; diff --git a/test/optional_test_emplace.cpp b/test/optional_test_emplace.cpp index 117f26c..9e7ed8a 100644 --- a/test/optional_test_emplace.cpp +++ b/test/optional_test_emplace.cpp @@ -145,11 +145,16 @@ void test_clear_on_throw() void test_no_assignment_on_emplacement() { - optional os; + optional os, ot; BOOST_TEST(!os); os.emplace("wow"); BOOST_TEST(os); BOOST_TEST_EQ(*os, "wow"); + + BOOST_TEST(!ot); + ot.emplace(); + BOOST_TEST(ot); + BOOST_TEST_EQ(*ot, ""); } int main() diff --git a/test/optional_test_swap.cpp b/test/optional_test_swap.cpp index b6802b1..dac7ae1 100644 --- a/test/optional_test_swap.cpp +++ b/test/optional_test_swap.cpp @@ -15,6 +15,7 @@ // #include "boost/optional/optional.hpp" +#include "boost/utility/in_place_factory.hpp" #ifdef __BORLANDC__ #pragma hdrstop