From 7e81da8d9a6e689e271f4f0450a69d8a14f515bb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 29 Aug 2021 17:17:23 +0300 Subject: [PATCH] Use metaprogramming constructs from std --- source/collection.h | 27 ++++++++++++++------------- source/loader.h | 5 +++-- source/loaderaction.h | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/source/collection.h b/source/collection.h index aa3c18a..473b58e 100644 --- a/source/collection.h +++ b/source/collection.h @@ -1,6 +1,7 @@ #ifndef MSP_DATAFILE_COLLECTION_H_ #define MSP_DATAFILE_COLLECTION_H_ +#include #include #include #include @@ -104,7 +105,7 @@ public: if(!item) throw std::invalid_argument("Collection::add(item)"); - typedef typename RemoveConst::Type NCT; + typedef typename std::remove_cv::type NCT; RefPtr ptr(item); try { @@ -122,7 +123,7 @@ public: template T &get(const std::string &name) const { - return extract::Type>(get_item(items, name)); + return extract::type>(get_item(items, name)); } /** Gets a typed object from the collection. If the name is not found, @@ -131,7 +132,7 @@ public: template T &get(const std::string &name) { - typedef typename RemoveConst::Type NCT; + typedef typename std::remove_cv::type NCT; return extract(get_var(name, get_type(name))); } @@ -142,13 +143,13 @@ public: T *find(const std::string &name) const { ItemMap::const_iterator i = items.find(name); - return (i!=items.end() ? extract::Type>(i->second) : 0); + return (i!=items.end() ? extract::type>(i->second) : 0); } template T *find(const std::string &name) { - typedef typename RemoveConst::Type NCT; + typedef typename std::remove_cv::type NCT; const Variant *var = find_var(name, get_type(name)); return (var ? &extract(*var) : 0); } @@ -187,7 +188,7 @@ public: std::list get_names() const { std::list names; - gather_items::Type>(0, &names, 0, false); + gather_items::type>(0, &names, 0, false); return names; } @@ -197,7 +198,7 @@ public: std::list get_names() { std::list names; - gather_items::Type>(0, &names, 0, true); + gather_items::type>(0, &names, 0, true); return names; } @@ -206,7 +207,7 @@ public: std::list get_list() const { std::vector vars; - gather_items::Type>(&vars, 0, 0, false); + gather_items::type>(&vars, 0, 0, false); return extract_list(vars); } @@ -215,12 +216,12 @@ public: template std::list get_list() { - CollectionItemTypeBase *type = get_type::Type>(); + CollectionItemTypeBase *type = get_type::type>(); if(type) load_items_from_sources(*type); std::vector vars; - gather_items::Type>(&vars, 0, type, true); + gather_items::type>(&vars, 0, type, true); return extract_list(vars); } @@ -242,19 +243,19 @@ public: /// Checks whether a typed object exists in the collection. template bool contains(const std::string &name) const - { return get_status::Type>(name)==1; } + { return get_status::type>(name)==1; } /** Checks whether a typed object exists in the collection or is loadable from a source. */ template bool contains(const std::string &name) - { return get_status::Type>(name)>0; } + { return get_status::type>(name)>0; } /// Returns the name of an item in the collection. template const std::string &get_name(T *d) const { - typedef RefPtr::Type> RPNCT; + typedef RefPtr::type> RPNCT; for(ItemMap::const_iterator i=items.begin(); i!=items.end(); ++i) if(i->second.check_type()) diff --git a/source/loader.h b/source/loader.h index 574ecce..926a2a1 100644 --- a/source/loader.h +++ b/source/loader.h @@ -1,6 +1,7 @@ #ifndef MSP_DATAFILE_LOADER_H_ #define MSP_DATAFILE_LOADER_H_ +#include #include #include #include "loaderaction.h" @@ -115,7 +116,7 @@ protected: /** Adds a keyword that is loaded by calling a function with a bound first argument. */ template - void add(const std::string &k, void (L::*func)(B0, Args...), const typename RemoveReference::Type &b0) + void add(const std::string &k, void (L::*func)(B0, Args...), const typename std::remove_reference::type &b0) { add(k, new LoaderFuncNBound1(func, b0)); } /** Adds a keyword that is loaded into a member of the loaded object. */ @@ -191,7 +192,7 @@ Loads an object from a file stored in a collection. The object must havea public Loader class. Any extra arguments are passed to the Loader constructor. */ template -typename EnableIf::value, void>::No load(T &obj, C &coll, const std::string &fn, Args &... args) +typename std::enable_if::value>::type load(T &obj, C &coll, const std::string &fn, Args &... args) { RefPtr in = coll.open_raw(fn); if(!in) diff --git a/source/loaderaction.h b/source/loaderaction.h index c7c5938..6931f48 100644 --- a/source/loaderaction.h +++ b/source/loaderaction.h @@ -234,7 +234,7 @@ class LoaderFuncNBound1: public LoaderAction { protected: typedef void (L::*FuncType)(B0, Args...); - typedef typename RemoveReference::Type Bound0Type; + typedef typename std::remove_reference::type Bound0Type; FuncType func; Bound0Type bound0; -- 2.45.2