From 070eaeef48a515786fc30ac518e75258c043bd75 Mon Sep 17 00:00:00 2001 From: Joachim Wuttke <j.wuttke@fz-juelich.de> Date: Fri, 26 Jul 2024 07:18:36 +0200 Subject: [PATCH] in template 'class' -> 'typename' --- Base/Math/IntegratorMCMiser.h | 15 ++++++++------- Base/Type/CloneableVector.h | 2 +- Base/Type/OwningVector.h | 2 +- Base/Type/VectorWC.h | 2 +- Base/Util/Vec.h | 11 ++++++----- Fit/Adapter/MinimizerAdapter.h | 12 ++++++------ Fit/Option/OptionContainer.h | 12 ++++++------ GUI/Model/FromCore/ItemizeSample.cpp | 6 +++--- GUI/Model/Type/ModelForSet.h | 4 ++-- GUI/Model/Type/SetWithModel.h | 2 +- GUI/View/IO/ComponentRW.cpp | 8 ++++---- GUI/View/IO/ComponentRW.h | 4 ++-- GUI/View/IO/DataLoader.cpp | 4 ++-- GUI/View/Scene/MaskGraphicsScene.cpp | 2 +- Param/Node/INode.h | 4 ++-- Resample/Interparticle/IInterparticleStrategy.h | 2 +- Sample/ComponentBuilder/IRegistry.h | 2 +- Sim/Export/ComponentKeyHandler.h | 4 ++-- Sim/Fitting/FitObserver.h | 12 ++++++------ Sim/Fitting/ObjectiveMetric.cpp | 2 +- Sim/Fitting/ObjectiveMetricUtil.cpp | 2 +- 21 files changed, 58 insertions(+), 56 deletions(-) diff --git a/Base/Math/IntegratorMCMiser.h b/Base/Math/IntegratorMCMiser.h index f6eb912dbc4..e2f7fa3b1e7 100644 --- a/Base/Math/IntegratorMCMiser.h +++ b/Base/Math/IntegratorMCMiser.h @@ -22,7 +22,8 @@ #include <memory> //! Alias template for member function with signature double f(double) -template <class T> using miser_integrand = double (T::*)(const double*, size_t, const void*) const; +template <typename T> +using miser_integrand = double (T::*)(const double*, size_t, const void*) const; //! Template class to use Monte Carlo MISER integration of class member functions. //! @@ -33,7 +34,7 @@ template <class T> using miser_integrand = double (T::*)(const double*, size_t, //! 'auto integrator = make_integrator_miser(this, mem_function, dimension)' //! - Call: 'integrator.integrate(lmin, lmax, data, n_points)' -template <class T> class IntegratorMCMiser { +template <typename T> class IntegratorMCMiser { public: //! structure holding the object and possible extra parameters struct CallBackHolder { @@ -67,11 +68,11 @@ private: }; //! Alias template for handle to a miser integrator -template <class T> using P_integrator_miser = std::unique_ptr<IntegratorMCMiser<T>>; +template <typename T> using P_integrator_miser = std::unique_ptr<IntegratorMCMiser<T>>; //! Template function to create an integrator object -template <class T> +template <typename T> P_integrator_miser<T> make_integrator_miser(const T* object, miser_integrand<T> mem_function, size_t dim) { @@ -83,7 +84,7 @@ P_integrator_miser<T> make_integrator_miser(const T* object, miser_integrand<T> // Implementation // ************************************************************************************************ -template <class T> +template <typename T> IntegratorMCMiser<T>::IntegratorMCMiser(const T* p_object, miser_integrand<T> p_member_function, size_t dim) : m_object(p_object) @@ -99,13 +100,13 @@ IntegratorMCMiser<T>::IntegratorMCMiser(const T* p_object, miser_integrand<T> p_ m_random_gen = gsl_rng_alloc(random_type); } -template <class T> IntegratorMCMiser<T>::~IntegratorMCMiser() +template <typename T> IntegratorMCMiser<T>::~IntegratorMCMiser() { gsl_monte_miser_free(m_gsl_workspace); gsl_rng_free(m_random_gen); } -template <class T> +template <typename T> double IntegratorMCMiser<T>::integrate(double* min_array, double* max_array, const void* params, size_t n_points) const { diff --git a/Base/Type/CloneableVector.h b/Base/Type/CloneableVector.h index 07716a65a37..19ae1f0a896 100644 --- a/Base/Type/CloneableVector.h +++ b/Base/Type/CloneableVector.h @@ -28,7 +28,7 @@ //! If the copy constructor or the copy assignment operator is used, //! then there must be a function T::clone(). -template <class T> class CloneableVector : public OwningVector<T> { +template <typename T> class CloneableVector : public OwningVector<T> { public: CloneableVector() = default; //! Constructor that takes over ownership of elements in given vector diff --git a/Base/Type/OwningVector.h b/Base/Type/OwningVector.h index 4d5590d1cd4..24d7f5ec72c 100644 --- a/Base/Type/OwningVector.h +++ b/Base/Type/OwningVector.h @@ -27,7 +27,7 @@ //! //! Cannot be copied. For a copyable vector of cloneable objects, use CloneableVector. -template <class T> class OwningVector { +template <typename T> class OwningVector { public: OwningVector() = default; //! Constructor that takes over ownership of elements in given vector diff --git a/Base/Type/VectorWC.h b/Base/Type/VectorWC.h index acb1b7bd2be..492f46fcf0b 100644 --- a/Base/Type/VectorWC.h +++ b/Base/Type/VectorWC.h @@ -23,7 +23,7 @@ //! An OwningVector with a current index. -template <class T> class VectorWC : public OwningVector<T> { +template <typename T> class VectorWC : public OwningVector<T> { using super = OwningVector<T>; public: diff --git a/Base/Util/Vec.h b/Base/Util/Vec.h index 4e408dacbcf..3c298004675 100644 --- a/Base/Util/Vec.h +++ b/Base/Util/Vec.h @@ -19,7 +19,7 @@ namespace Vec { -template <class T, class S> int indexOfPtr(const T* t, const std::vector<S*>& v) +template <typename T, class S> int indexOfPtr(const T* t, const std::vector<S*>& v) { for (size_t i = 0; i < v.size(); i++) if (v[i] == t) @@ -27,7 +27,7 @@ template <class T, class S> int indexOfPtr(const T* t, const std::vector<S*>& v) return -1; } -template <class T, class S> bool containsPtr(const T* t, const std::vector<S*>& v) +template <typename T, class S> bool containsPtr(const T* t, const std::vector<S*>& v) { for (size_t i = 0; i < v.size(); i++) if (v[i] == t) @@ -35,12 +35,12 @@ template <class T, class S> bool containsPtr(const T* t, const std::vector<S*>& return false; } -template <class C> void concat(std::vector<C>& v, const std::vector<C>& w) +template <typename C> void concat(std::vector<C>& v, const std::vector<C>& w) { v.insert(v.end(), w.begin(), w.end()); } -template <class C> std::vector<C> flatten(const std::vector<std::vector<C>>& src) +template <typename C> std::vector<C> flatten(const std::vector<std::vector<C>>& src) { std::vector<C> result; for (const auto& row : src) @@ -48,7 +48,8 @@ template <class C> std::vector<C> flatten(const std::vector<std::vector<C>>& src return result; } -template <class C> std::vector<std::vector<C>> reshapeTo2D(const std::vector<C>& src, size_t n_rows) +template <typename C> +std::vector<std::vector<C>> reshapeTo2D(const std::vector<C>& src, size_t n_rows) { size_t n_cols = src.size() / n_rows; std::vector<std::vector<C>> result(n_rows); diff --git a/Fit/Adapter/MinimizerAdapter.h b/Fit/Adapter/MinimizerAdapter.h index caac59b431e..de8cfcae584 100644 --- a/Fit/Adapter/MinimizerAdapter.h +++ b/Fit/Adapter/MinimizerAdapter.h @@ -89,13 +89,13 @@ protected: virtual const root_minimizer_t* rootMinimizer() const = 0; root_minimizer_t* rootMinimizer(); - template <class T> + template <typename T> OptionContainer::option_t addOption(const std::string& optionName, T value, const std::string& description = ""); - template <class T> void setOptionValue(const std::string& optionName, T value); + template <typename T> void setOptionValue(const std::string& optionName, T value); - template <class T> T optionValue(const std::string& optionName) const; + template <typename T> T optionValue(const std::string& optionName) const; private: MinimizerOptions m_options; @@ -104,19 +104,19 @@ private: bool m_status; }; -template <class T> +template <typename T> OptionContainer::option_t MinimizerAdapter::addOption(const std::string& optionName, T value, const std::string& description) { return m_options.addOption(optionName, value, description); } -template <class T> void MinimizerAdapter::setOptionValue(const std::string& optionName, T value) +template <typename T> void MinimizerAdapter::setOptionValue(const std::string& optionName, T value) { m_options.setOptionValue(optionName, value); } -template <class T> T MinimizerAdapter::optionValue(const std::string& optionName) const +template <typename T> T MinimizerAdapter::optionValue(const std::string& optionName) const { return m_options.optionValue<T>(optionName); } diff --git a/Fit/Option/OptionContainer.h b/Fit/Option/OptionContainer.h index 9f773d6d57a..a54428459af 100644 --- a/Fit/Option/OptionContainer.h +++ b/Fit/Option/OptionContainer.h @@ -37,16 +37,16 @@ public: OptionContainer(const OptionContainer& other); OptionContainer& operator=(const OptionContainer& other); - template <class T> + template <typename T> option_t addOption(const std::string& optionName, T value, const std::string& description = ""); option_t option(const std::string& optionName); option_t option(const std::string& optionName) const; - template <class T> T optionValue(const std::string& optionName) const; + template <typename T> T optionValue(const std::string& optionName) const; //! Sets the value of option. Option should hold same value type already. - template <class T> void setOptionValue(const std::string& optionName, T value); + template <typename T> void setOptionValue(const std::string& optionName, T value); iterator begin() { return m_options.begin(); } const_iterator begin() const { return m_options.begin(); } @@ -63,7 +63,7 @@ protected: container_t m_options; }; -template <class T> +template <typename T> OptionContainer::option_t OptionContainer::addOption(const std::string& optionName, T value, const std::string& description) { @@ -76,12 +76,12 @@ OptionContainer::option_t OptionContainer::addOption(const std::string& optionNa return result; } -template <class T> T OptionContainer::optionValue(const std::string& optionName) const +template <typename T> T OptionContainer::optionValue(const std::string& optionName) const { return option(optionName)->get<T>(); } -template <class T> void OptionContainer::setOptionValue(const std::string& optionName, T value) +template <typename T> void OptionContainer::setOptionValue(const std::string& optionName, T value) { option(optionName)->value() = value; if (option(optionName)->value().index() != option(optionName)->defaultValue().index()) diff --git a/GUI/Model/FromCore/ItemizeSample.cpp b/GUI/Model/FromCore/ItemizeSample.cpp index 23a06deeb6e..ae5d1ce37be 100644 --- a/GUI/Model/FromCore/ItemizeSample.cpp +++ b/GUI/Model/FromCore/ItemizeSample.cpp @@ -74,7 +74,7 @@ void set_PDF1D(InterferenceRadialParacrystalItem* parent, const IProfile1D* ipdf // note: SetterPDF(1|2)Type are needed because template template parameter must be classes -template <class T> struct SetterPDF1Type { +template <typename T> struct SetterPDF1Type { T* operator()(Interference2DParacrystalItem* parent) { auto* p = new T; @@ -83,7 +83,7 @@ template <class T> struct SetterPDF1Type { } }; -template <class T> struct SetterPDF2Type { +template <typename T> struct SetterPDF2Type { T* operator()(Interference2DParacrystalItem* parent) { auto* p = new T; @@ -92,7 +92,7 @@ template <class T> struct SetterPDF2Type { } }; -template <template <class T> class U> +template <template <typename T> class U> void set_PDF2D(Interference2DParacrystalItem* parent, const IProfile2D* pdf) { if (const auto* pdf_cauchy = dynamic_cast<const Profile2DCauchy*>(pdf)) { diff --git a/GUI/Model/Type/ModelForSet.h b/GUI/Model/Type/ModelForSet.h index 77faf442a4e..d6fb18318de 100644 --- a/GUI/Model/Type/ModelForSet.h +++ b/GUI/Model/Type/ModelForSet.h @@ -18,11 +18,11 @@ #include "GUI/Model/Type/PredefinedColors.h" #include <QAbstractListModel> -template <class T> class SetWithModel; +template <typename T> class SetWithModel; //! Data model for a set of NamedItem%s. -template <class T> class ModelForSet : public QAbstractListModel { +template <typename T> class ModelForSet : public QAbstractListModel { public: explicit ModelForSet(SetWithModel<T>* set) : m_set(set) diff --git a/GUI/Model/Type/SetWithModel.h b/GUI/Model/Type/SetWithModel.h index 7d1748e0ef6..404793c458c 100644 --- a/GUI/Model/Type/SetWithModel.h +++ b/GUI/Model/Type/SetWithModel.h @@ -47,7 +47,7 @@ signals: //! A set of NamedItem%s that has a current item and a QListModel. -template <class T> class SetWithModel : public AbstractSetModel { +template <typename T> class SetWithModel : public AbstractSetModel { public: SetWithModel() : m_qmodel(std::make_unique<ModelForSet<T>>(this)) diff --git a/GUI/View/IO/ComponentRW.cpp b/GUI/View/IO/ComponentRW.cpp index b3134d7938e..eaf286055e6 100644 --- a/GUI/View/IO/ComponentRW.cpp +++ b/GUI/View/IO/ComponentRW.cpp @@ -22,8 +22,8 @@ namespace { -template <class T> void saveToXML(const QString& fname, const T* t); -template <class T> T* loadFromXML(const QString& fname); +template <typename T> void saveToXML(const QString& fname, const T* t); +template <typename T> T* loadFromXML(const QString& fname); template <> void saveToXML<InstrumentItem>(const QString& fname, const InstrumentItem* t) { @@ -41,7 +41,7 @@ auto dummy_saveXML_InstrumentItem = &IO::saveComponentToXML<class InstrumentItem auto dummy_loadXML_InstrumentItem = &IO::loadComponentFromXML<class InstrumentItem>; -template <class T> void IO::saveComponentToXML(const QString& type, const T* t) +template <typename T> void IO::saveComponentToXML(const QString& type, const T* t) { if (!t) return; @@ -60,7 +60,7 @@ template <class T> void IO::saveComponentToXML(const QString& type, const T* t) } } -template <class T> T* IO::loadComponentFromXML(const QString& type) +template <typename T> T* IO::loadComponentFromXML(const QString& type) { QString fname = QFileDialog::getOpenFileName(gApp->mainWindow, "Load " + type, gApp->xml_dir, "XML files (*.xml)", nullptr); diff --git a/GUI/View/IO/ComponentRW.h b/GUI/View/IO/ComponentRW.h index 377bdce9737..95fc690cf90 100644 --- a/GUI/View/IO/ComponentRW.h +++ b/GUI/View/IO/ComponentRW.h @@ -19,8 +19,8 @@ namespace IO { -template <class T> void saveComponentToXML(const QString& type, const T* t); -template <class T> T* loadComponentFromXML(const QString& type); +template <typename T> void saveComponentToXML(const QString& type, const T* t); +template <typename T> T* loadComponentFromXML(const QString& type); } // namespace IO diff --git a/GUI/View/IO/DataLoader.cpp b/GUI/View/IO/DataLoader.cpp index 63d49a90a13..3ecda7f7850 100644 --- a/GUI/View/IO/DataLoader.cpp +++ b/GUI/View/IO/DataLoader.cpp @@ -30,7 +30,7 @@ namespace { // The following two functions are templated on T in {IO::Filetype1D, IO::Filetype2D}. -template <class T> +template <typename T> QString join_filterkeys(std::vector<std::pair<const QString, T>> _nomap, const QString& _separator) { QString result; @@ -42,7 +42,7 @@ QString join_filterkeys(std::vector<std::pair<const QString, T>> _nomap, const Q return result; } -template <class T> +template <typename T> T filterkey2type(std::vector<std::pair<const QString, T>> _nomap, const QString& _key) { for (const auto& it : _nomap) diff --git a/GUI/View/Scene/MaskGraphicsScene.cpp b/GUI/View/Scene/MaskGraphicsScene.cpp index 57cd10cbca3..779a099ad94 100644 --- a/GUI/View/Scene/MaskGraphicsScene.cpp +++ b/GUI/View/Scene/MaskGraphicsScene.cpp @@ -36,7 +36,7 @@ namespace { const qreal min_distance_to_create_rect = 10; //! Return true if area beneath the mouse contains views of given type. -template <class T> bool areaContains(QVector<QGraphicsItem*> items) +template <typename T> bool areaContains(QVector<QGraphicsItem*> items) { for (QGraphicsItem* item : items) if (dynamic_cast<T*>(item)) diff --git a/Param/Node/INode.h b/Param/Node/INode.h index 845a84427c0..3860ead303d 100644 --- a/Param/Node/INode.h +++ b/Param/Node/INode.h @@ -83,7 +83,7 @@ protected: #ifndef SWIG -template <class T> +template <typename T> std::vector<const INode*>& operator<<(std::vector<const INode*>& v_node, const std::unique_ptr<T>& node) { @@ -92,7 +92,7 @@ std::vector<const INode*>& operator<<(std::vector<const INode*>& v_node, return v_node; } -template <class T> +template <typename T> std::vector<const INode*>& operator<<(std::vector<const INode*>&& v_node, const std::unique_ptr<T>& node) { diff --git a/Resample/Interparticle/IInterparticleStrategy.h b/Resample/Interparticle/IInterparticleStrategy.h index 8ce6fc5f2bd..046d68cc9f4 100644 --- a/Resample/Interparticle/IInterparticleStrategy.h +++ b/Resample/Interparticle/IInterparticleStrategy.h @@ -24,7 +24,7 @@ #include <memory> #include <vector> -template <class T> class IntegratorMCMiser; +template <typename T> class IntegratorMCMiser; class CoheringSubparticles; class DiffuseElement; diff --git a/Sample/ComponentBuilder/IRegistry.h b/Sample/ComponentBuilder/IRegistry.h index 4e0b40a46c1..2993a64e72d 100644 --- a/Sample/ComponentBuilder/IRegistry.h +++ b/Sample/ComponentBuilder/IRegistry.h @@ -26,7 +26,7 @@ //! Templated object registry. -template <class T> class IRegistry { +template <typename T> class IRegistry { public: const T* getItem(const std::string& key) const { diff --git a/Sim/Export/ComponentKeyHandler.h b/Sim/Export/ComponentKeyHandler.h index 77d0e4947d5..69015cd3bcb 100644 --- a/Sim/Export/ComponentKeyHandler.h +++ b/Sim/Export/ComponentKeyHandler.h @@ -30,14 +30,14 @@ class ComponentKeyHandler { public: void insertModel(const std::string& tag, const INode* s); - template <class T> std::vector<const T*> objectsOfType() const; + template <typename T> std::vector<const T*> objectsOfType() const; std::string obj2key(const INode* s) const; private: std::map<std::string, std::vector<const INode*>> m_objects; }; -template <class T> std::vector<const T*> ComponentKeyHandler::objectsOfType() const +template <typename T> std::vector<const T*> ComponentKeyHandler::objectsOfType() const { std::vector<const T*> result; for (const auto& it : m_objects) diff --git a/Sim/Fitting/FitObserver.h b/Sim/Fitting/FitObserver.h index 807aeb78917..411086ee5c2 100644 --- a/Sim/Fitting/FitObserver.h +++ b/Sim/Fitting/FitObserver.h @@ -25,7 +25,7 @@ //! Contains collection of observers and call them at specified intervals. //! Each observer will be called at first iteration and every-nth iterations. -template <class T> class FitObserver { +template <typename T> class FitObserver { public: using observer_t = std::function<void(const T&)>; FitObserver(); @@ -63,19 +63,19 @@ private: int m_notify_count; //! Total number of notify calls }; -template <class T> +template <typename T> FitObserver<T>::FitObserver() : m_notify_count(0) { } -template <class T> +template <typename T> void FitObserver<T>::addObserver(int every_nth, FitObserver<T>::observer_t&& observer) { m_observers.emplace_back(ObserverData(every_nth, observer)); } -template <class T> void FitObserver<T>::notify(const T& data) +template <typename T> void FitObserver<T>::notify(const T& data) { for (const auto& observer : m_observers) { if (need_notify(observer.m_every_nth)) @@ -85,7 +85,7 @@ template <class T> void FitObserver<T>::notify(const T& data) m_notify_count++; } -template <class T> void FitObserver<T>::notify_all(const T& data) +template <typename T> void FitObserver<T>::notify_all(const T& data) { for (const auto& observer : m_observers) observer.m_observer(data); @@ -93,7 +93,7 @@ template <class T> void FitObserver<T>::notify_all(const T& data) m_notify_count++; } -template <class T> bool FitObserver<T>::need_notify(int every_nth) +template <typename T> bool FitObserver<T>::need_notify(int every_nth) { return every_nth && m_notify_count % every_nth == 0; } diff --git a/Sim/Fitting/ObjectiveMetric.cpp b/Sim/Fitting/ObjectiveMetric.cpp index 652cccfc31c..6ffa3bb4bbd 100644 --- a/Sim/Fitting/ObjectiveMetric.cpp +++ b/Sim/Fitting/ObjectiveMetric.cpp @@ -27,7 +27,7 @@ const double double_max = std::numeric_limits<double>::max(); const double double_min = std::numeric_limits<double>::min(); const double ln10 = std::log(10.0); -template <class T> T* copyMetric(const T& metric) +template <typename T> T* copyMetric(const T& metric) { auto* result = new T; result->setNorm(metric.norm()); diff --git a/Sim/Fitting/ObjectiveMetricUtil.cpp b/Sim/Fitting/ObjectiveMetricUtil.cpp index d92ce4f7853..484c97a0c5e 100644 --- a/Sim/Fitting/ObjectiveMetricUtil.cpp +++ b/Sim/Fitting/ObjectiveMetricUtil.cpp @@ -36,7 +36,7 @@ const std::map<std::string, std::function<double(double)>> norm_factory = {{"l1" {"l2", l2_norm}}; const std::string default_norm_name = "l2"; -template <class U> std::vector<std::string> keys(const std::map<std::string, U>& map) +template <typename U> std::vector<std::string> keys(const std::map<std::string, U>& map) { std::vector<std::string> result; result.reserve(map.size()); -- GitLab