Skip to content
This repository has been archived by the owner on Aug 27, 2019. It is now read-only.

gcc 4.6 and clang 3.3 support #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A library for optional (nullable) objects for C++11. This is the reference imple
Supported compilers
-------------------

Clang 3.2, G++ 4.7.2 (and probably later)
Clang 3.2+, G++ 4.6+


Usage
Expand Down
31 changes: 22 additions & 9 deletions optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,45 @@
# define REQUIRES(...) typename enable_if<__VA_ARGS__::value, bool>::type = false

# if defined __clang__
# define OPTIONAL_HAS_USING 1
# if (__clang_major__ > 2) || (__clang_major__ == 2) && (__clang_minor__ >= 9)
# define OPTIONAL_HAS_THIS_RVALUE_REFS 1
# else
# define OPTIONAL_HAS_THIS_RVALUE_REFS 0
# endif
# elif defined __GNUC__
# if (__GNUC__ >= 4) && (__GNUC_MINOR__ > 8 || ((__GNUC_MINOR__ >= 8) && (__GNUC_PATCHLEVEL__ >= 1)))
# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7))
# define OPTIONAL_HAS_USING 1
# else
# define OPTIONAL_HAS_USING 0
# endif
# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 8 || ((__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ >= 1))))
# define OPTIONAL_HAS_THIS_RVALUE_REFS 1
# else
# define OPTIONAL_HAS_THIS_RVALUE_REFS 0
# endif
# else
# define OPTIONAL_HAS_THIS_RVALUE_REFS 0
# define OPTIONAL_HAS_USING 0
# endif


namespace std{


# if (defined __GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 8)
# if (defined __GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))
// leave it; our metafunctions are already defined.
# elif (defined __clang__) && ((__clang_major__ > 3) || (__clang_major__ == 3) && (__clang_minor__ >= 3))
// leave it; our metafunctions are already defined.
# else


// the only bit GCC 4.7 and clang(?) don't have
# if OPTIONAL_HAS_USING
// the only bit GCC 4.7 and clang 3.2 don't have
template <class T>
using is_trivially_destructible = typename std::has_trivial_destructor<T>;
# endif


# if (defined __GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 7)
# if (defined __GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 7)))
// leave it; remaining metafunctions are already defined.
# elif defined __clang__
// leave it; remaining metafunctions are already defined.
Expand Down Expand Up @@ -295,14 +304,16 @@ struct constexpr_optional_base
~constexpr_optional_base() = default;
};

# if OPTIONAL_HAS_USING
template <class T>
using OptionalBase = typename std::conditional<
std::is_trivially_destructible<T>::value,
constexpr_optional_base<T>,
optional_base<T>
>::type;


# else
# define OptionalBase optional_base
# endif

template <class T>
class optional : private OptionalBase<T>
Expand Down Expand Up @@ -930,6 +941,8 @@ namespace std
};
}


#ifdef OptionalBase
# undef OptionalBase
#endif

# endif //___OPTIONAL_HPP___