From faf53e5fdda42a40959dda689532af6f030d9fa2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 11 Jun 2015 18:36:04 +0200 Subject: Add optional implementation --- build/.gitignore | 1 + build/bootstrap.build | 6 ++++++ build/export.build | 6 ++++++ build/root.build | 8 ++++++++ buildfile | 7 +++++++ butl/buildfile | 6 ++++++ butl/dummy.cxx | 0 butl/optional | 39 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 73 insertions(+) create mode 100644 build/.gitignore create mode 100644 build/bootstrap.build create mode 100644 build/export.build create mode 100644 build/root.build create mode 100644 buildfile create mode 100644 butl/buildfile create mode 100644 butl/dummy.cxx create mode 100644 butl/optional diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..225c27f --- /dev/null +++ b/build/.gitignore @@ -0,0 +1 @@ +config.build diff --git a/build/bootstrap.build b/build/bootstrap.build new file mode 100644 index 0000000..4dd58c5 --- /dev/null +++ b/build/bootstrap.build @@ -0,0 +1,6 @@ +# file : build/bootstrap.build +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +project = libbutl +using config diff --git a/build/export.build b/build/export.build new file mode 100644 index 0000000..e887a6f --- /dev/null +++ b/build/export.build @@ -0,0 +1,6 @@ +$out_root/: +{ + include butl/ +} + +export $out_root/butl/lib{butl} diff --git a/build/root.build b/build/root.build new file mode 100644 index 0000000..dc1c297 --- /dev/null +++ b/build/root.build @@ -0,0 +1,8 @@ +# file : build/root.build +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +using cxx + +cxx.std = 14 +cxx.poptions += -I$src_root diff --git a/buildfile b/buildfile new file mode 100644 index 0000000..3248471 --- /dev/null +++ b/buildfile @@ -0,0 +1,7 @@ +# file : buildfile +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file + +d = butl/ tests/ +.: $d +include $d 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 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 + 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 -- cgit v1.1