Mirror reflection library 0.5.13

mirror/meta_prog/optional.hpp

Go to the documentation of this file.
00001 
00010 #ifndef MIRROR_META_PROG_OPTIONAL_1104130956_HPP
00011 #define MIRROR_META_PROG_OPTIONAL_1104130956_HPP
00012 
00013 #include <mirror/meta_prog/forward_decl.hpp>
00014 #include <mirror/meta_prog/nil_type.hpp>
00015 #include <mirror/meta_prog/traits.hpp>
00016 
00017 MIRROR_NAMESPACE_BEGIN
00018 namespace mp {
00019 
00021 
00027 template <typename T>
00028 struct optional
00029 {
00030     typedef optional type;
00031 };
00032 
00034 typedef optional<nil_t> nil_optional;
00035 
00036 #ifdef MIRROR_DOCUMENTATION_ONLY
00037 
00038 
00044 template <typename Optional>
00045 struct nil { };
00046 #else
00047 // The default implementation of the empty meta-function
00048 template <typename X>
00049 struct nil : nil<typename X::type>::type
00050 {
00051     MIRROR_ASSERT_RETURNS_OPTIONAL(X);
00052 };
00053 #endif
00054 
00055 template <>
00056 struct nil<nil_optional>
00057  : std::true_type
00058 { };
00059 
00060 template <typename T>
00061 struct nil<optional<T> >
00062  : std::false_type
00063 { };
00064 
00065 #ifdef MIRROR_DOCUMENTATION_ONLY
00066 
00067 
00075 template <typename Optional>
00076 struct get
00077 {
00079     typedef unspecified_type type;
00080 };
00081 #else
00082 template <typename X>
00083 struct get
00084 {
00085     MIRROR_ASSERT_RETURNS_OPTIONAL(X);
00086     typedef typename get<typename X::type>::type type;
00087 };
00088 #endif
00089 
00090 template <typename T>
00091 struct get<optional<T> >
00092 {
00093     typedef T type;
00094 };
00095 
00096 namespace aux {
00097 
00098 template <typename Expr, typename IsOptional>
00099 struct as_optional;
00100 
00101 template <typename Optional>
00102 struct as_optional<Optional, std::true_type>
00103 {
00104     typedef Optional type;
00105 };
00106 
00107 template <typename Expr>
00108 struct as_optional<Expr, std::false_type>
00109 {
00110     MIRROR_ASSERT_RETURNS_OPTIONAL(Expr);
00111     typedef typename Expr::type type;
00112 };
00113 
00114 } // namespace aux
00115 
00116 template <typename Expr>
00117 struct as_optional : public aux::as_optional<
00118     Expr,
00119     typename is_optional<Expr>::type
00120 >{ };
00121 
00122 
00123 } // namespace mp
00124 MIRROR_NAMESPACE_END
00125 
00126 #endif //include guard
00127 

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.