From 56ddc859f5ff8283d076d9e4b9ba7512c2cf48f7 Mon Sep 17 00:00:00 2001 From: Simon Praetorius <simon.praetorius@tu-dresden.de> Date: Mon, 6 May 2019 11:21:26 +0200 Subject: [PATCH] add fake container-like datastructure with all no-op --- src/amdis/common/CMakeLists.txt | 1 + src/amdis/common/FakeContainer.hpp | 72 ++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/amdis/common/FakeContainer.hpp diff --git a/src/amdis/common/CMakeLists.txt b/src/amdis/common/CMakeLists.txt index 89f2d370..676d8869 100644 --- a/src/amdis/common/CMakeLists.txt +++ b/src/amdis/common/CMakeLists.txt @@ -10,6 +10,7 @@ install(FILES Concepts.hpp ConceptsBase.hpp ConcurrentCache.hpp + FakeContainer.hpp FieldMatVec.hpp FieldMatVec.inc.hpp Filesystem.hpp diff --git a/src/amdis/common/FakeContainer.hpp b/src/amdis/common/FakeContainer.hpp new file mode 100644 index 00000000..52048b46 --- /dev/null +++ b/src/amdis/common/FakeContainer.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include <cstddef> + +namespace AMDiS +{ + struct FakeAssigner + { + template <class T> + FakeAssigner& operator=(T&&) { return *this; } + + template <class T> + FakeAssigner& operator+=(T&&) { return *this; } + + template <class T> + FakeAssigner& operator-=(T&&) { return *this; } + + template <class T> + FakeAssigner& operator*=(T&&) { return *this; } + + template <class T> + FakeAssigner& operator/=(T&&) { return *this; } + }; + + /// A container-like data-structure not storing anything and with empty + /// implementations in many container-interface functions. + /** + * This container that *does nothing* can be used as a dummy argument to + * functions expecting a container, in order to ommit specializations of + * these functions for not providing a container. + **/ + class FakeContainer + : public FakeAssigner + { + public: + using size_type = std::size_t; + + template <class... Args> + FakeContainer(Args&&...) {} + + template <class Arg> + void push_back(Arg&&) {} + + template <class... Args> + void emplace_back(Args&&...) {} + + void reserve(size_type) {} + void resize(size_type) {} + + /// This container is always empty + bool empty() const { return true; } + size_type size() const { return 0u; } + + /// Mutable *element* access does return the container itself + /// This allows to emulate nested containers + FakeContainer& operator[](size_type) { return *this; } + + /// Assignment operators from a fake assigner + using FakeAssigner::operator=; + using FakeAssigner::operator+=; + using FakeAssigner::operator-=; + using FakeAssigner::operator*=; + using FakeAssigner::operator/=; + + FakeAssigner front() { return {}; } + FakeAssigner back() { return {}; } + + friend inline FakeAssigner front(FakeContainer&) { return {}; } + friend inline FakeAssigner back(FakeContainer&) { return {}; } + }; + +} // end namespace AMDiS -- GitLab