diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-11 18:36:04 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-06-11 18:36:04 +0200 |
commit | faf53e5fdda42a40959dda689532af6f030d9fa2 (patch) | |
tree | 029268e46d6bc607292e53c8d04b09fabd92266f /butl | |
parent | 4224a2fc7a046d26a94faf8b848595bdc8f0cee3 (diff) |
Add optional implementation
Diffstat (limited to 'butl')
-rw-r--r-- | butl/buildfile | 6 | ||||
-rw-r--r-- | butl/dummy.cxx | 0 | ||||
-rw-r--r-- | butl/optional | 39 |
3 files changed, 45 insertions, 0 deletions
diff --git a/butl/buildfile b/butl/buildfile new file mode 100644 index 0000000..5ccc75a --- /dev/null +++ b/butl/buildfile @@ -0,0 +1,6 @@ +# file : butl/buildfile +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +lib{butl}: cxx{dummy} +lib{butl}: cxx.export.poptions = -I$src_root diff --git a/butl/dummy.cxx b/butl/dummy.cxx new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/butl/dummy.cxx diff --git a/butl/optional b/butl/optional new file mode 100644 index 0000000..fc34b33 --- /dev/null +++ b/butl/optional @@ -0,0 +1,39 @@ +// file : butl/optional -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BUTL_OPTIONAL +#define BUTL_OPTIONAL + +namespace butl +{ + // Simple optional class template while waiting for std::optional. + // + template <typename T> + class optional + { + public: + typedef T value_type; + + optional (): null_ (true) {} + optional (const T& v): value_ (v), null_ (false) {} + optional& operator= (const T& v) {value_ = v; null_ = false; return *this;} + + T& value () {return value_;} + const T& value () const {return value_;} + + T* operator-> () {return &value_;} + const T* operator-> () const {return &value_;} + + T& operator* () {return value_;} + const T& operator* () const {return value_;} + + explicit operator bool () const {return !null_;} + + private: + T value_; + bool null_; + }; +} + +#endif // BUTL_OPTIONAL |