#ifndef CNOID_STDX_OPTIONAL_HEADER
#define CNOID_STDX_OPTIONAL_HEADER

#if __cplusplus > 201402L
#include <optional>
namespace cnoid::stdx {
using std::optional;
using std::nullopt;

template<class T, class... Args>
T& emplace(optional<T>& opt, Args&&... args){
    return opt.emplace(args...);
}
template<class T>
T& emplace(optional<T>& opt){
    return opt.emplace();
}

}

#else
#include <boost/version.hpp>
#include <boost/optional.hpp>
#include <boost/utility/in_place_factory.hpp>
namespace cnoid { namespace stdx {
using boost::optional;
namespace {
#if BOOST_VERSION >= 106000
const boost::none_t nullopt ((boost::none_t::init_tag()));
#else
const boost::none_t& nullopt = boost::detail::optional_detail::none_instance<boost::none_t>::instance;
#endif

template<class T, class... Args>
T& emplace(optional<T>& opt, Args&&... args){
    opt = boost::in_place(args...);
    return *opt;
}
template<class T>
T& emplace(optional<T>& opt){
    opt = boost::in_place();
    return *opt;
}

}

} }

#endif

#endif
