diff --git a/CMakeLists.txt b/CMakeLists.txt index 92c6edd7..e43cd359 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,6 +288,7 @@ list ( cmdopt.hpp colour.cpp colour.hpp + container.hpp coord.hpp coord/fwd.hpp coord/base.hpp diff --git a/container.hpp b/container.hpp new file mode 100644 index 00000000..0d203bdd --- /dev/null +++ b/container.hpp @@ -0,0 +1,32 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 2020, Danny Robson + */ + +#pragma once + +#include +#include + +namespace cruft { + /// Tests if a value is present in a container. + /// + /// Defaults to a naive search of the container. + /// + /// \return true if the value is present in the container, otherwise false. + template + bool + contains (ValueT &&value, ContainerT &&container) + { + auto const pos = std::find ( + std::cbegin (container), + std::cend (container), + std::move (value) + ); + + return pos != std::cend (container); + } +} \ No newline at end of file