diff --git a/include/gp/flat_tree.hpp b/include/gp/flat_tree.hpp index 0e3632e..2ddbc37 100644 --- a/include/gp/flat_tree.hpp +++ b/include/gp/flat_tree.hpp @@ -2,6 +2,7 @@ #include #include #include +// UNIMPLEMENTED: see filename template class flat_tree { diff --git a/include/gp/memory.hpp b/include/gp/memory.hpp index 90220bd..0aae5cc 100644 --- a/include/gp/memory.hpp +++ b/include/gp/memory.hpp @@ -2,6 +2,7 @@ #include "gp_config.hpp" #include "gp/exception.hpp" #include +// XXX: THIS FILE SHOULD BE REMOVED, AS SHOULD ALL DEPENDENCIES ON THE C-ALLOCATOR AS IS namespace gp{ template> diff --git a/include/gp/optional.hpp b/include/gp/optional.hpp index 6080629..000ec54 100644 --- a/include/gp/optional.hpp +++ b/include/gp/optional.hpp @@ -2,6 +2,7 @@ #include #include "gp_config.hpp" #include "gp/exception.hpp" +#include "gp/algorithm/move.hpp" #include "gp/memory.hpp" namespace gp{ @@ -9,6 +10,7 @@ namespace gp{ constexpr nullopt_t nullopt; + // TODO: Add allocators to the template template::value || std::is_fundamental::value> class optional; @@ -34,9 +36,38 @@ namespace gp{ constexpr optional(T&& value) : ready{true} { - new(buffer) T(std::move(value)); + new(buffer) T(gp::move(value)); } + optional operator=(nullopt_t) { + if(ready) { + ((T*)buffer)->~T(); + ready = false; + } + return *this; + } + + optional operator=(T& value) { + if(ready) { + *(T*)buffer = value; + } else { + ready = true; + new(buffer) T(value); + } + return *this; + } + + optional operator=(T&& value) { + if(ready) { + *(T*)buffer = gp::move(value); + } else { + ready = true; + new(buffer) T(gp::move(value)); + } + return *this; + } + + constexpr bool has_value() { return ready; @@ -50,11 +81,14 @@ namespace gp{ { throw bad_optional{}; } + } else { + gp_config::assertion(ready, "bad optional access"); } return *reinterpret_cast(buffer); } }; + // TODO: Add allocators to the template template class optional{ bool ready = false; @@ -68,16 +102,48 @@ namespace gp{ : ready{false} {} + // TODO: Add typesafe generic assignment constexpr optional(T& value) : ready{true} { - ptr = (void*)new T(value); + ptr = (void*)new T(value); // TODO: Use allocators } + // TODO: Add typesafe generic assignment constexpr optional(T&& value) : ready{true} { - ptr = (void*)new T(std::move(value)); + ptr = (void*)new T(gp::move(value)); // TODO: Use allocators + } + + optional operator=(nullopt_t) { + if(ready) { + delete (T*)ptr; + ready = false; + } + return *this; + } + + // TODO: Add typesafe generic assignment + optional operator=(T& value) { + if(ready) { + *(T*)ptr = value; + } else { + ready = true; + ptr = (void*)new T(value); // TODO: Use allocators + } + return *this; + } + + // TODO: Add typesafe generic assignment + optional operator=(T&& value) { + if(ready) { + *(T*)ptr = gp::move(value); + } else { + ready = true; + ptr = (void*)new T(gp::move(value)); // TODO: Use allocators + } + return *this; } constexpr bool has_value() @@ -93,6 +159,8 @@ namespace gp{ { throw bad_optional{}; } + } else { + gp_config::assertion(ready, "bad optional access"); } return *reinterpret_cast(ptr); } diff --git a/include/gp/subtree_iterator.hpp b/include/gp/subtree_iterator.hpp index d2b432b..c36bf72 100644 --- a/include/gp/subtree_iterator.hpp +++ b/include/gp/subtree_iterator.hpp @@ -2,6 +2,7 @@ #include #include #include +// UNIMPLEMENTED: see filename template struct subtree_iterator final diff --git a/include/indexed_array.hpp b/include/indexed_array.hpp index 3f59c93..b394313 100644 --- a/include/indexed_array.hpp +++ b/include/indexed_array.hpp @@ -1,2 +1,2 @@ #pragma once - +// UNIMPLEMENTED: see filename \ No newline at end of file diff --git a/include/rc6_generic.hpp b/include/rc6_generic.hpp index 38825a1..b265b7b 100644 --- a/include/rc6_generic.hpp +++ b/include/rc6_generic.hpp @@ -4,7 +4,7 @@ #include #include #include - +// BUG: A proper investigation is required to fix this file so that it gives the correct output. template diff --git a/include/region_locker.hpp b/include/region_locker.hpp index 3f59c93..b394313 100644 --- a/include/region_locker.hpp +++ b/include/region_locker.hpp @@ -1,2 +1,2 @@ #pragma once - +// UNIMPLEMENTED: see filename \ No newline at end of file diff --git a/include/shared_fd.hpp b/include/shared_fd.hpp index e585161..98b8cff 100644 --- a/include/shared_fd.hpp +++ b/include/shared_fd.hpp @@ -14,6 +14,8 @@ #include #include +// TODO: Scavenge for useful parts and discard + namespace gp{ using open_opt_flags = int; diff --git a/include/shared_mmap.hpp b/include/shared_mmap.hpp index 3f59c93..b394313 100644 --- a/include/shared_mmap.hpp +++ b/include/shared_mmap.hpp @@ -1,2 +1,2 @@ #pragma once - +// UNIMPLEMENTED: see filename \ No newline at end of file diff --git a/include/stored_array.hpp b/include/stored_array.hpp index 7b9637e..b394313 100644 --- a/include/stored_array.hpp +++ b/include/stored_array.hpp @@ -1 +1,2 @@ -#pragma once \ No newline at end of file +#pragma once +// UNIMPLEMENTED: see filename \ No newline at end of file diff --git a/include/stored_clog.hpp b/include/stored_clog.hpp index 3f59c93..b394313 100644 --- a/include/stored_clog.hpp +++ b/include/stored_clog.hpp @@ -1,2 +1,2 @@ #pragma once - +// UNIMPLEMENTED: see filename \ No newline at end of file diff --git a/include/stored_hmap.hpp b/include/stored_hmap.hpp index 3f59c93..b394313 100644 --- a/include/stored_hmap.hpp +++ b/include/stored_hmap.hpp @@ -1,2 +1,2 @@ #pragma once - +// UNIMPLEMENTED: see filename \ No newline at end of file diff --git a/include/stored_indexed_array.hpp b/include/stored_indexed_array.hpp index 7b9637e..b394313 100644 --- a/include/stored_indexed_array.hpp +++ b/include/stored_indexed_array.hpp @@ -1 +1,2 @@ -#pragma once \ No newline at end of file +#pragma once +// UNIMPLEMENTED: see filename \ No newline at end of file