diff --git a/src/util/optional.hpp b/src/util/optional.hpp index 7dd65a278f0efbb7c0bd88c8729e0d8f734b5f11..f1fb805bfb86062f1c7c603befd5f01d54fad5f2 100644 --- a/src/util/optional.hpp +++ b/src/util/optional.hpp @@ -1,3 +1,5 @@ +#pragma once + /*! \file optional.h * \brief An option class with a monadic interface. * @@ -14,9 +16,6 @@ * is the lack of constexpr versions of the methods and constructors. */ -#ifndef UTIL_OPTIONAL_H_ -#define UTIL_OPTIONAL_H_ - #include <type_traits> #include <stdexcept> #include <utility> @@ -43,8 +42,8 @@ struct nothing_t {}; constexpr nothing_t nothing{}; namespace detail { - template <typename Y> struct lift_type { typedef optional<Y> type; }; - template <typename Y> struct lift_type<optional<Y>> { typedef optional<Y> type; }; + template <typename Y> struct lift_type { using type=optional<Y>; }; + template <typename Y> struct lift_type<optional<Y>> { using type=optional<Y>; }; struct optional_tag {}; @@ -52,23 +51,23 @@ namespace detail { enum {value=std::is_base_of<optional_tag,typename std::decay<X>::type>::value }; }; - template <typename D,typename X> struct wrapped_type_ { typedef X type; }; - template <typename D,typename X> struct wrapped_type_<optional<D>,X> { typedef D type; }; + template <typename D,typename X> struct wrapped_type_ { using type=X; }; + template <typename D,typename X> struct wrapped_type_<optional<D>,X> { using type=D; }; - template <typename X> struct wrapped_type { typedef typename wrapped_type_<typename std::decay<X>::type,X>::type type; }; + template <typename X> struct wrapped_type { using type=typename wrapped_type_<typename std::decay<X>::type,X>::type; }; template <typename X> struct optional_base: detail::optional_tag { template <typename Y> friend struct optional; protected: - typedef util::uninitialized<X> D; + using D=util::uninitialized<X>; public: - typedef typename D::reference_type reference_type; - typedef typename D::const_reference_type const_reference_type; - typedef typename D::pointer_type pointer_type; - typedef typename D::const_pointer_type const_pointer_type; + using reference_type=typename D::reference_type; + using const_reference_type=typename D::const_reference_type; + using pointer_type=typename D::pointer_type; + using const_pointer_type=typename D::const_pointer_type; protected: bool set; @@ -118,8 +117,8 @@ namespace detail { template <typename F> auto bind(F &&f) -> typename lift_type<decltype(data.apply(std::forward<F>(f)))>::type { - typedef decltype(data.apply(std::forward<F>(f))) F_result_type; - typedef typename lift_type<F_result_type>::type result_type; + using F_result_type=decltype(data.apply(std::forward<F>(f))); + using result_type=typename lift_type<F_result_type>::type; if (!set) return result_type(); else return bind_impl<result_type,std::is_same<F_result_type,void>::value>::bind(data,std::forward<F>(f)); @@ -127,8 +126,8 @@ namespace detail { template <typename F> auto bind(F &&f) const -> typename lift_type<decltype(data.apply(std::forward<F>(f)))>::type { - typedef decltype(data.apply(std::forward<F>(f))) F_result_type; - typedef typename lift_type<F_result_type>::type result_type; + using F_result_type=decltype(data.apply(std::forward<F>(f))); + using result_type=typename lift_type<F_result_type>::type; if (!set) return result_type(); else return bind_impl<result_type,std::is_same<F_result_type,void>::value>::bind(data,std::forward<F>(f)); @@ -158,7 +157,7 @@ namespace detail { template <typename X> struct optional: detail::optional_base<X> { - typedef detail::optional_base<X> base; + using base=detail::optional_base<X>; using base::set; using base::ref; using base::reset; @@ -224,7 +223,7 @@ struct optional: detail::optional_base<X> { template <typename X> struct optional<X &>: detail::optional_base<X &> { - typedef detail::optional_base<X &> base; + using base=detail::optional_base<X &>; using base::set; using base::ref; using base::data; @@ -257,7 +256,7 @@ struct optional<X &>: detail::optional_base<X &> { template <> struct optional<void>: detail::optional_base<void> { - typedef detail::optional_base<void> base; + using base=detail::optional_base<void>; using base::set; optional(): base() {} @@ -299,7 +298,7 @@ typename std::enable_if< optional<typename detail::wrapped_type<B>::type> >::type operator&(A &&a,B &&b) { - typedef optional<typename detail::wrapped_type<B>::type> result_type; + using result_type=optional<typename detail::wrapped_type<B>::type>; return a?b:result_type(); } @@ -309,5 +308,3 @@ template <typename X> optional<X> just(X &&x) { return optional<X>(std::forward<X>(x)); } }}} // namespace nest::mc::util - -#endif // ndef UTIL_OPTIONALM_H_ diff --git a/src/util/uninitialized.hpp b/src/util/uninitialized.hpp index 17ab7d38982fa9a30f45651834a8b4e3c5c57f69..26ebcf90ef2c94ea0645ccb7d3a94f6a01fb2510 100644 --- a/src/util/uninitialized.hpp +++ b/src/util/uninitialized.hpp @@ -1,3 +1,5 @@ +#pragma once + /* Represent a possibly-uninitialized value, reference or void. * * The uninitialized<X> structure holds space for an item of @@ -7,9 +9,6 @@ * allow for the handling of non-value types in a uniform manner. */ -#ifndef UTIL_UNINITIALIZED_H_ -#define UTIL_UNINITIALIZED_H_ - namespace nest { namespace mc { namespace util { @@ -23,10 +22,10 @@ private: typename std::aligned_storage<sizeof(X),alignof(X)>::type data; public: - typedef X *pointer_type; - typedef const X *const_pointer_type; - typedef X &reference_type; - typedef const X &const_reference_type; + using pointer_type=X *; + using const_pointer_type=const X *; + using reference_type=X &; + using const_reference_type=const X &; pointer_type ptr() { return reinterpret_cast<X *>(&data); } const_pointer_type cptr() const { return reinterpret_cast<const X *>(&data); } @@ -64,10 +63,10 @@ private: X *data; public: - typedef X *pointer_type; - typedef const X *const_pointer_type; - typedef X &reference_type; - typedef const X &const_reference_type; + using pointer_type=X *; + using const_pointer_type=const X *; + using reference_type=X &; + using const_reference_type=const X &; pointer_type ptr() { return data; } const_pointer_type cptr() const { return data; } @@ -92,10 +91,10 @@ public: */ template <> struct uninitialized<void> { - typedef void *pointer_type; - typedef const void *const_pointer_type; - typedef void reference_type; - typedef void const_reference_type; + using pointer_type=void *; + using const_pointer_type=const void *; + using reference_type=void; + using const_reference_type=void; pointer_type ptr() { return nullptr; } const_pointer_type cptr() const { return nullptr; } @@ -127,5 +126,3 @@ struct uninitialized_can_construct<void,Y...>: std::true_type {}; }}} // namespace nest::mc::util -#endif // ndef UTIL_UNINITIALIZED_H_ -