Skip to content

Commit fa20902

Browse files
Optional cleanup
1 parent c351aee commit fa20902

14 files changed

+18
-519
lines changed

doc/cppdevtk_api.chm

-7.72 KB
Binary file not shown.

include/cppdevtk/base/optional.hpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
#include "logger.hpp"
2929
#include "exception.hpp"
3030
#include "cassert.hpp"
31+
#include "static_assert.hpp"
3132

3233
#include <cstddef>
3334
#include <new>
3435
#include <algorithm> // swap(), C++98
3536
#include <utility> // swap(), C++11
37+
#include CPPDEVTK_TR1_HEADER(type_traits)
3638

3739

3840
namespace cppdevtk {
@@ -69,7 +71,7 @@ static const NullOptT kNullOpt = (static_cast<NullOptT>(NULL)) ;
6971
/// - C++ 17 std says that if an ::std::optional<T> contains a value, the value is guaranteed to be allocated
7072
/// as part of the optional object footprint, i.e. no dynamic memory allocation ever takes place.
7173
/// Our implementation currently use dynamic memory allocation (need for public API and no time for proper implementation...)!
72-
/// - Reference types are not supported!
74+
/// - Reference types are not supported (C++ 17 ::std::optional does not support references, ::boost::optional does)!
7375
/// \sa
7476
/// - <a href="http://en.cppreference.com/w/cpp/utility/optional">C++17 optional</a>
7577
/// - <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4562.html#optional.object">C++ Extensions for Library Fundamentals, Version 2, 5.3 optional for object types</a>
@@ -78,6 +80,10 @@ static const NullOptT kNullOpt = (static_cast<NullOptT>(NULL)) ;
7880
template <typename TValue>
7981
class Optional {
8082
public:
83+
CPPDEVTK_STATIC_ASSERT(!CPPDEVTK_TR1_NS::is_reference<TValue>::value);
84+
CPPDEVTK_STATIC_ASSERT((!CPPDEVTK_TR1_NS::is_same<TValue, NullOptT>::value));
85+
86+
8187
typedef TValue ValueType;
8288
typedef void (*UnspecifiedBoolType)();
8389

@@ -361,6 +367,7 @@ void Optional<TValue>::Reset() CPPDEVTK_NOEXCEPT {
361367
CPPDEVTK_LOG_FATAL("Optional::Reset(): destructor of TValue (" << typeid(TValue).name()
362368
<< ") threw exception: " << Exception::GetDetailedInfo(exc));
363369
CPPDEVTK_ASSERT(0 && "Optional::Reset(): destructor of TValue threw exception");
370+
SuppressUnusedWarning(exc);
364371
terminate();
365372
}
366373
catch (...) {

include/cppdevtk/base/static_assert.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939

4040
#if (CPPDEVTK_HAVE_CPP11_STATIC_ASSERT)
4141
# define CPPDEVTK_STATIC_ASSERT_W_MSG(expr, msg) \
42-
static_assert(expr, msg)
42+
static_assert((expr), msg)
4343

4444
# define CPPDEVTK_STATIC_ASSERT(expr) \
45-
static_assert(expr, #expr)
45+
static_assert((expr), "static assert failed: " #expr)
4646
#else // (CPPDEVTK_HAVE_CPP11_STATIC_ASSERT)
4747
# define CPPDEVTK_STATIC_ASSERT_W_MSG(expr, msg) \
4848
CPPDEVTK_STATIC_ASSERT(expr)

src/base/any.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <cppdevtk/base/exception.hpp>
2222
#include <cppdevtk/base/logger.hpp>
2323
#include <cppdevtk/base/cassert.hpp>
24+
#include <cppdevtk/base/unused.hpp>
2425

2526
#include <typeinfo>
2627

@@ -49,6 +50,7 @@ void Any::Reset() CPPDEVTK_NOEXCEPT {
4950
CPPDEVTK_LOG_FATAL("Any::Reset(): destructor of TypeErasedValue (" << typeid(*pTypeErasedValue_).name()
5051
<< ") threw exception: " << Exception::GetDetailedInfo(exc));
5152
CPPDEVTK_ASSERT(0 && "Any::Reset(): destructor of TypeErasedValue threw exception");
53+
SuppressUnusedWarning(exc);
5254
terminate();
5355
}
5456
catch (...) {

src/base/condition_variable_std.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
#if (CPPDEVTK_DISABLE_CPPDEVTK_WARNINGS && CPPDEVTK_COMPILER_MSVC)
3636
# pragma warning(disable: 4459) // C4459: declaration of 'item' hides global declaration
37+
# pragma warning(disable: 4702) // C4702: unreachable code
3738
#endif
3839

3940

test/test_base/boost_test_optional/optional_test.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -204,27 +204,26 @@ void test_conditional_ctor_and_get_valur_or ( T const* )
204204
T& rb = o0.GetValueOr(rz);
205205
BOOST_TEST_OPTIONAL_CHECK( rb == b ) ;
206206

207-
#if (CPPDEVTK_OPTIONAL_SUPPORTS_REF)
207+
// our Optional does not support references
208+
/*
208209
T& ra = a ;
209210
210211
Optional<T&> defref(false,ra);
211212
BOOST_TEST_OPTIONAL_CHECK(!defref);
212213
213214
Optional<T&> ref(true,ra);
214215
BOOST_TEST_OPTIONAL_CHECK(!!ref);
215-
#endif
216216
217217
a = T(432);
218218
219-
#if (CPPDEVTK_OPTIONAL_SUPPORTS_REF)
220219
BOOST_TEST_OPTIONAL_CHECK( *ref == a ) ;
221220
222221
T& r1 = defref.GetValueOr(z);
223222
BOOST_TEST_OPTIONAL_CHECK( r1 == z ) ;
224223
225224
T& r2 = ref.GetValueOr(z);
226225
BOOST_TEST_OPTIONAL_CHECK( r2 == a ) ;
227-
#endif
226+
*/
228227
}
229228

230229
//
@@ -1019,8 +1018,6 @@ class CustomAddressOfClass
10191018
bool operator== (CustomAddressOfClass const& that) const { return n == that.n; }
10201019
};
10211020

1022-
#if (CPPDEVTK_OPTIONAL_SUPPORTS_ADDRESS_OF)
1023-
10241021
void test_custom_addressof_operator()
10251022
{
10261023
cppdevtk::base::Optional< CustomAddressOfClass > o1(CustomAddressOfClass(10));
@@ -1035,8 +1032,6 @@ void test_custom_addressof_operator()
10351032
BOOST_TEST_OPTIONAL_CHECK(!o1);
10361033
}
10371034

1038-
#endif
1039-
10401035
bool TestOptional() {
10411036
try {
10421037
test_with_class_type();
@@ -1045,9 +1040,7 @@ bool TestOptional() {
10451040
test_conversions1();
10461041
test_conversions2();
10471042
//test_swap_tweaking();
1048-
#if (CPPDEVTK_OPTIONAL_SUPPORTS_ADDRESS_OF)
10491043
test_custom_addressof_operator();
1050-
#endif
10511044
}
10521045
catch (const ::std::exception& exc) {
10531046
::std::cerr << "OptionalTest(): caught exception: " << exc.what() << ::std::endl;

test/test_base/boost_test_optional/optional_test_common.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#include <iostream>
2828

2929

30-
#define CPPDEVTK_OPTIONAL_SUPPORTS_REF 0 // FIXME
31-
#define CPPDEVTK_OPTIONAL_SUPPORTS_ADDRESS_OF 0 // FIXME
3230
#define CPPDEVTK_TEST_OPTIONAL_VERIFY_LIFETIME 0 // FIXME
3331
#define CPPDEVTK_TEST_OPTIONAL_ENABLE_TRACE 0
3432

0 commit comments

Comments
 (0)