mirror of
https://github.com/boostorg/optional.git
synced 2025-07-14 21:06:37 +02:00
63 lines
1.5 KiB
C++
63 lines
1.5 KiB
C++
![]() |
// Copyright (C) 2019 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
|
||
|
|
||
|
template <typename, typename>
|
||
|
struct void_t
|
||
|
{
|
||
|
typedef void type;
|
||
|
};
|
||
|
|
||
|
|
||
|
template <typename T, typename = void>
|
||
|
struct trait
|
||
|
{
|
||
|
};
|
||
|
|
||
|
// the following trait emulates properties std::iterator_traits
|
||
|
template <typename T>
|
||
|
struct trait<T, BOOST_DEDUCED_TYPENAME void_t<BOOST_DEDUCED_TYPENAME T::value_type,
|
||
|
BOOST_DEDUCED_TYPENAME boost::enable_if<boost::is_constructible<T, T&> >::type
|
||
|
>::type>
|
||
|
{
|
||
|
typedef BOOST_DEDUCED_TYPENAME T::value_type value_type;
|
||
|
};
|
||
|
|
||
|
// This class emulates the properties of std::filesystem::path
|
||
|
struct Path
|
||
|
{
|
||
|
template <typename T, typename = BOOST_DEDUCED_TYPENAME trait<T>::value_type>
|
||
|
Path(T const&);
|
||
|
};
|
||
|
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_IS_CONSTRUCTIBLE_TRAIT
|
||
|
#ifndef BOOST_OPTIONAL_DETAIL_NO_SFINAE_FRIENDLY_CONSTRUCTORS
|
||
|
|
||
|
boost::optional<Path> optFs1;
|
||
|
boost::optional<Path> optFs2;
|
||
|
|
||
|
optFs1 = optFs2;
|
||
|
|
||
|
// the following still fails although it shouldn't
|
||
|
//BOOST_STATIC_ASSERT((std::is_copy_constructible<boost::optional<Path>>::value));
|
||
|
|
||
|
#endif
|
||
|
#endif
|
||
|
}
|