diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a3939b3..47c2e823 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ include(EkatUtils) IsDebugBuild(EKAT_IS_DEBUG_BUILD) set (EKAT_VERSION_MAJOR 2) -set (EKAT_VERSION_MINOR 0) +set (EKAT_VERSION_MINOR 1) set (EKAT_VERSION_PATCH 0) message(STATUS "EKAT version: ${EKAT_VERSION_MAJOR}.${EKAT_VERSION_MINOR}.${EKAT_VERSION_PATCH}") diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 29b5337a..5dc3bb6d 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -111,8 +111,6 @@ set (HEADERS ekat_rational_constant.hpp ekat_scalar_traits.hpp ekat_scaling_factor.hpp - ekat_std_any.hpp - ekat_std_enable_shared_from_this.hpp ekat_std_map_key_iterator.hpp ekat_std_type_traits.hpp ekat_std_utils.hpp diff --git a/src/core/ekat_parameter_list.hpp b/src/core/ekat_parameter_list.hpp index 823e6c91..7b37af2b 100644 --- a/src/core/ekat_parameter_list.hpp +++ b/src/core/ekat_parameter_list.hpp @@ -16,7 +16,7 @@ namespace ekat { * A parameter list store two things: parameters, and sublists. * Each of these is stored in a map, which uses a string as key. * - * Parameters are stored using ekat::any, which allows to store pretty + * Parameters are stored using std::any, which allows to store pretty * much anything you want in the list. However, this means that when * you try to retrieve a parameter, you must already know what the * type is, or else the any_cast will throw. You can specify the type diff --git a/src/core/ekat_std_any.hpp b/src/core/ekat_std_any.hpp deleted file mode 100644 index 0156a9e9..00000000 --- a/src/core/ekat_std_any.hpp +++ /dev/null @@ -1,209 +0,0 @@ -#ifndef EKAT_STD_ANY_HPP -#define EKAT_STD_ANY_HPP - -/* - * Emulating c++1z features - * - * This file contains an implementation of the 'any' concept, which is implemented - * in the std library in c++17. - * Since we have limited access to c++1z standard on target platforms, - * we can only rely on c++11 features. So we try to emulate std::any here. - */ - -#include "ekat_std_utils.hpp" -#include "ekat_type_traits.hpp" -#include "ekat_assert.hpp" - -#include -#include -#include - -namespace ekat { - -// ================ std::any ================= // - -class [[deprecated("ekat::any will be removed in future releases; please, use std::any instead.")]] -any { - - // Implementation detail of the any class - class holder_base { - public: - virtual ~holder_base() = default; - - virtual const std::type_info& type () const = 0; - - virtual void print (std::ostream& os) const = 0; - - virtual holder_base* clone () const = 0; - }; - - template - class holder : public holder_base { - public: - - template - static holder* create(const Args&... args) { - holder* ptr = new holder(); - ptr->m_value = std::make_shared(args...); - return ptr; - } - - template - static - typename std::enable_if::value,holder*>::type - create(std::shared_ptr ptr_in) - { - holder* ptr = new holder(); - ptr->m_value = ptr_in; - return ptr; - } - - const std::type_info& type () const { return typeid(HeldType); } - - HeldType& value () { return *m_value; } - std::shared_ptr ptr () const { return m_value; } - - holder_base* clone () const override { - return create(*m_value); - } - - void print (std::ostream& os) const { - if (static_cast(m_value)) { - print_impl(os); - } - } - private: - holder () = default; - - template - typename std::enable_if::value>::type - print_impl (std::ostream& os) const { - - os << "Error! Trying to print object of type '" << type().name() << "'," - << " which does not overload operator<< .\n"; - } - - template - typename std::enable_if::value>::type - print_impl (std::ostream& os) const { - os << *m_value; - } - - // Note: we store a shared_ptr rather than a HeldType directly, - // since we may store multiple copies of the concrete object. - // Since we don't know if the actual object is copiable, we need - // to store copiable pointers (hence, cannot use unique_ptr). - std::shared_ptr m_value; - }; - -public: - - any () = default; - template - any (const T& t) { - reset (t); - } - - template - void reset (Args... args) { - m_content.reset( holder::create(args...) ); - } - - template - void reset (const T& t) { - m_content.reset( holder::create(t) ); - } - - holder_base& content () const { - EKAT_REQUIRE_MSG (static_cast(m_content), "Error! Object not yet initialized.\n"); - return *m_content; - } - - holder_base* content_ptr () const { - return m_content.get(); - } - - template - bool isType () const { - return std::type_index(content().type())==std::type_index(typeid(ConcreteType)); - } - - any clone() const { - any a; - a.m_content = std::shared_ptr(m_content->clone()); - return a; - } - - template - friend ConcreteType& any_cast (any&); - - template - friend const ConcreteType& any_cast (const any&); - - template - friend std::shared_ptr any_ptr_cast (any&); - -private: - - std::shared_ptr m_content; -}; - -template -ConcreteType& any_cast (any& src) { - - EKAT_REQUIRE_MSG(src.isType(), - "Error! Invalid cast requested.\n" - " - actual type: " + std::string(src.content().type().name()) + "\n" - " - requested type: " + std::string(typeid(ConcreteType).name()) + "'.\n"); - - any::holder* ptr = dynamic_cast*>(src.content_ptr()); - - EKAT_REQUIRE_MSG(ptr!=nullptr, - "Error! Failed dynamic_cast during any_cast.\n" - " This is an internal problem, please, contact developers.\n"); - - return ptr->value(); -} - -template -const ConcreteType& any_cast (const any& src) { - EKAT_REQUIRE_MSG(src.isType(), - "Error! Invalid cast requested.\n" - " - actual type: " + std::string(src.content().type().name()) + "\n" - " - requested type: " + std::string(typeid(ConcreteType).name()) + "'.\n"); - - any::holder* ptr = dynamic_cast*>(src.content_ptr()); - - EKAT_REQUIRE_MSG(ptr!=nullptr, - "Error! Failed dynamic_cast during any_cast.\n" - " This is an internal problem, please, contact developers.\n"); - - return ptr->value(); -} - -template -std::shared_ptr any_ptr_cast (any& src) { - EKAT_REQUIRE_MSG(src.isType(), - "Error! Invalid cast requested.\n" - " - actual type: " + std::string(src.content().type().name()) + "\n" - " - requested type: " + std::string(typeid(ConcreteType).name()) + "'.\n"); - - any::holder* ptr = dynamic_cast*>(src.content_ptr()); - - EKAT_REQUIRE_MSG(ptr!=nullptr, - "Error! Failed dynamic_cast during any_cast.\n" - " This is an internal problem, please, contact developers.\n"); - - return ptr->ptr(); -} - -// Overload stream operator -inline std::ostream& operator<< (std::ostream& out, const any& any) { - any.content().print(out); - - return out; -} - -} // namespace ekat - -#endif // EKAT_STD_ANY_HPP diff --git a/src/core/ekat_std_enable_shared_from_this.hpp b/src/core/ekat_std_enable_shared_from_this.hpp deleted file mode 100644 index 568b1ff4..00000000 --- a/src/core/ekat_std_enable_shared_from_this.hpp +++ /dev/null @@ -1,72 +0,0 @@ -#ifndef EKAT_STD_ENABLE_SHARED_FROM_THIS_HPP -#define EKAT_STD_ENABLE_SHARED_FROM_THIS_HPP - -#include - -#include "ekat_assert.hpp" - -namespace ekat { - -// ================= std::enable_shared_from_this =============== // - -/* - * README - * - * This class already exists in c++11. However, there's an important - * feature missing in c++11, which will be available only in c++17: - * when calling the shared_from_this() method, it is crucial that the - * object is indeed owned by a shared_ptr. If not, undef behavior will - * ensue. This check is (implicitly) present in c++17 (but not before), - * guaranteed by the fact that the class stores a weak_ptr, which is - * assigned to during the shared_ptr constructor. Since we cannot change the - * content of std::shared_ptr's constructor, to achieve the desired result, - * one needs to manually set the self pointer upon shared_ptr construction. - * I thought about rolling our own make_shared routine, which would do that, - * but there is a problem. The way to check if a newly constructed shared_ptr - * points to something that inherits from enable_shared_from_this, is to - * try to cast to it. But to do so, you need to know what T is. - * Example: say you have a class A inheriting from - * enable_shared_from_this. Then you have B inheriting from A. When - * you try to do make_shared(args...), we have no knowledge of the - * base classes of B (there's no reflection mechanism yet in c++11 or c++17, - * for that matter). All we can check is whether class B inherits from - * enable_shared_from_this, which would fail. Adding an extra template - * parameter to make_shared would make the signature of the function - * too different from the one in the std namespace, making the switch - * from make_shared to std::make_shared in the future too complicated. - * Long story short: use enable_shared_from_this, but be diligent, - * and set it up correctly when you create a shared_ptr (assuming you want - * to exploit the feature of enable_shared_from_this). - */ - -template -class [[deprecated("ekat::enable_shared_from_this will be removed in future releases; please, use std::enable_shared_from_this instead.")]] -enable_shared_from_this -{ -public: - - enable_shared_from_this () = default; - virtual ~enable_shared_from_this () = default; - - std::shared_ptr shared_from_this () const noexcept { - return m_self.lock(); - } - - std::weak_ptr weak_from_this () const noexcept { - return m_self; - } - - // Make sure the input pointer is indeed a pointer to self - void setSelfPointer (const std::shared_ptr& ptr) { - EKAT_REQUIRE_MSG(ptr.get()==this, "Error! Cannot set self pointer to something different from 'this'.\n"); - m_self = ptr; - } - -protected: - - std::weak_ptr m_self; -}; - -} // namespace ekat - -#endif // EKAT_STD_ENABLE_SHARED_FROM_THIS_HPP diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 4c36e312..2692d860 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -54,10 +54,6 @@ EkatCreateUnitTest(comm comm.cpp EkatCreateUnitTest(units units.cpp LIBS ekat::Core) -# Test std_meta stuff -EkatCreateUnitTest(std_meta std_meta.cpp - LIBS ekat::Core) - # Test meta utilities EkatCreateUnitTest(meta_utils meta_utils.cpp LIBS ekat::Core) diff --git a/tests/core/std_meta.cpp b/tests/core/std_meta.cpp deleted file mode 100644 index 087fdb71..00000000 --- a/tests/core/std_meta.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include - -#include "ekat_std_any.hpp" - -#include - -TEST_CASE ("any") { - - ekat::any a,b; - - std::vector u = {1,2}; - - a.reset>(u); - b.reset(u); - - REQUIRE (ekat::any_cast>(a)==ekat::any_cast>(b)); - REQUIRE (ekat::any_cast>(a)==u); - REQUIRE_THROWS (ekat::any_cast>(a)); - - REQUIRE (a.isType>()); - REQUIRE (not a.isType()); - - ekat::any c (u); - REQUIRE (ekat::any_cast>(a)==ekat::any_cast>(c)); -}