00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __CONSTANT_HH
00018 # define __CONSTANT_HH
00019
00020 # include "pattern.hh"
00021
00022
00023 namespace aurelia {
00024
00025 template <typename T>
00026 struct constant {
00027 private:
00028 T value;
00029
00030 public:
00031 constant() = delete;
00032 constant(const constant& v): value(v.value) {
00033 }
00034
00035 constant(constant&& v): value(std::move(v.value)) {
00036 }
00037
00038 constant(const T& v): value(v) {
00039 }
00040
00041 constant(T&& v): value(std::move(v)) {
00042 }
00043
00044 template <typename U,
00045 typename = typename
00046 std::enable_if<std::is_convertible<U, T>::value>::type>
00047 constant(const U& v): value(v) {}
00048
00049 template <typename U,
00050 typename = typename
00051 std::enable_if<std::is_convertible<U, T>::value>::type>
00052 constant(U&& v): value(std::move(v)) {}
00053
00054 const T& operator*() const {
00055 return value;
00056 }
00057
00058 const T& operator=(const T& c) const {
00059 if (value != c)
00060 throw failure();
00061 return value;
00062 }
00063
00064 };
00065
00068 template <typename T>
00069 struct pattern_model<constant<T> > {
00070 struct model {
00071 typedef constant<T> type;
00072 typedef T build_type;
00073 };
00074 };
00075
00076 template <typename T>
00077 struct listable_model<constant<T> > {
00078 struct model {
00079 typedef constant<T> type;
00080 };
00081 };
00082
00083 }
00084
00085 #endif