diff --git a/doc/21_ref_none.qbk b/doc/21_ref_none.qbk
index e3b921e..011eff7 100644
--- a/doc/21_ref_none.qbk
+++ b/doc/21_ref_none.qbk
@@ -15,14 +15,16 @@
```
namespace boost {
-class none_t {};
+class none_t {/* see below */};
-extern const none_t none; // see below
+const none_t none (/* see below */);
} // namespace boost
```
-Variable `none` has external linkage, however it is not required to link with any library to obtain its definition. Only by including this header file, the definition becomes available, by means of using template instantiation.
+Class `none_t` is meant to serve as a tag for selecting appropriate overloads of from `optional`'s interface. It is an empty, trivially copyable class with disabled default constructor.
+
+Constant `none` is used to indicate an optional object that does not contain a value in initialization, assignment and relational operations of `optional`.
[endsect]
diff --git a/doc/html/index.html b/doc/html/index.html
index 2b0d9fd..833a9f6 100644
--- a/doc/html/index.html
+++ b/doc/html/index.html
@@ -146,7 +146,7 @@
-Last revised: July 08, 2015 at 21:39:55 GMT |
+Last revised: October 01, 2015 at 13:19:55 GMT |
|
diff --git a/doc/html/optional/reference.html b/doc/html/optional/reference.html
index 242e029..0cc575c 100644
--- a/doc/html/optional/reference.html
+++ b/doc/html/optional/reference.html
@@ -52,19 +52,23 @@
namespace boost {
-class none_t {};
+class none_t {/* see below */};
-extern const none_t none;
+const none_t none (/* see below */);
}
- Variable none
has external
- linkage, however it is not required to link with any library to obtain
- its definition. Only by including this header file, the definition becomes
- available, by means of using template instantiation.
+ Class none_t
is meant to
+ serve as a tag for selecting appropriate overloads of from optional
's interface. It is an empty,
+ trivially copyable class with disabled default constructor.
+
+
+ Constant none
is used to
+ indicate an optional object that does not contain a value in initialization,
+ assignment and relational operations of optional
.
diff --git a/include/boost/none.hpp b/include/boost/none.hpp
index 87a6c70..db744e5 100644
--- a/include/boost/none.hpp
+++ b/include/boost/none.hpp
@@ -22,8 +22,10 @@
namespace boost {
#ifdef BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE
+
none_t const none = (static_cast(0)) ;
-#else
+
+#elif defined BOOST_OPTIONAL_USE_SINGLETON_DEFINITION_OF_NONE
namespace detail { namespace optional_detail {
@@ -45,9 +47,13 @@ namespace {
const none_t& none = detail::optional_detail::none_instance::instance;
}
-#endif
+#else
+
+const none_t none ((none_t::init_tag()));
+
+#endif // older definitions
} // namespace boost
-#endif
+#endif // header guard
diff --git a/include/boost/none_t.hpp b/include/boost/none_t.hpp
index 13ce455..608cb0c 100644
--- a/include/boost/none_t.hpp
+++ b/include/boost/none_t.hpp
@@ -16,13 +16,25 @@
namespace boost {
#ifdef BOOST_OPTIONAL_USE_OLD_DEFINITION_OF_NONE
+
namespace detail { struct none_helper{}; }
typedef int detail::none_helper::*none_t ;
-#else
+
+#elif defined BOOST_OPTIONAL_USE_SINGLETON_DEFINITION_OF_NONE
+
class none_t {};
-#endif
+
+#else
+
+struct none_t
+{
+ struct init_tag{};
+ explicit none_t(init_tag){} // to prevent default constructor
+};
+
+#endif // old implementation workarounds
} // namespace boost
-#endif
+#endif // header guard
diff --git a/include/boost/optional/optional_io.hpp b/include/boost/optional/optional_io.hpp
index 16dbf95..ce81b68 100644
--- a/include/boost/optional/optional_io.hpp
+++ b/include/boost/optional/optional_io.hpp
@@ -15,7 +15,7 @@
#include
#include
-#include
+#include "boost/none.hpp"
#include "boost/optional/optional.hpp"
@@ -25,7 +25,7 @@ namespace boost
template
inline
std::basic_ostream&
-operator<<(std::basic_ostream& out, none_t const&)
+operator<<(std::basic_ostream& out, none_t)
{
if (out.good())
{
diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
index ea9e81b..6b4e857 100644
--- a/test/Jamfile.v2
+++ b/test/Jamfile.v2
@@ -58,6 +58,7 @@ import testing ;
[ compile-fail optional_test_fail_explicit_convert_in_value_or.cpp ]
[ compile-fail optional_test_fail_explicit_convert_in_value_or_call.cpp ]
[ compile-fail optional_test_fail_io_without_io.cpp ]
+ [ compile-fail optional_test_fail_none_io_without_io.cpp ]
[ compile-fail optional_test_fail_convert_assign_of_enums.cpp ]
;
}
diff --git a/test/optional_test_fail_none_io_without_io.cpp b/test/optional_test_fail_none_io_without_io.cpp
new file mode 100644
index 0000000..7fa19a9
--- /dev/null
+++ b/test/optional_test_fail_none_io_without_io.cpp
@@ -0,0 +1,23 @@
+// Copyright (C) 2015, 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
+#include "boost/none.hpp"
+// but no boost/optional/optional_io.hpp
+
+// THIS TEST SHOULD FAIL TO COMPILE
+// Unless one includes header boost/optional/optional_io.hpp, it should not be possible
+// to stream out boost::none.
+
+void test_streaming_out_none()
+{
+ std::cout << boost::none;
+}
\ No newline at end of file