From f1985c17a1391460d9b646e6cc804c9b2fe87cbe Mon Sep 17 00:00:00 2001 From: Daniel Greenwald Date: Thu, 13 Apr 2017 17:08:46 +0200 Subject: [PATCH 1/4] c++11 -> c++14 --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ed4d923..abb47465 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,14 +21,14 @@ endif() # Default C++ flags include(CheckCXXCompilerFlag) -CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11) +CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14) # CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X) if (COMPILER_SUPPORTS_CXX11) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") # elseif(COMPILER_SUPPORTS_CXX0X) # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") else() - message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") + message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.") endif() CHECK_CXX_COMPILER_FLAG("-fdiagnostics-color=always" COMPILER_SUPPORTS_DIAGNOSTIC_COLORS) From 6f73f4e18f2ee4fb2d773032db970b540a534841 Mon Sep 17 00:00:00 2001 From: Daniel Greenwald Date: Thu, 13 Apr 2017 17:10:07 +0200 Subject: [PATCH 2/4] -make_unique.h --- examples/bat_gen/models/d3pi.h | 1 - examples/bat_gen/models/d4pi.h | 1 - examples/bat_gen/models/dkkpi.h | 1 - examples/bat_gen/runBatFit.cxx | 1 - examples/bat_gen/runBatFitFitFractions.cxx | 1 - examples/bat_gen/runBatGen.cxx | 1 - examples/bat_gen/runFitFractions.cxx | 1 - examples/bat_gen/tools.h | 1 - examples/programs/D3piTest.cxx | 1 - examples/programs/D4piTest.cxx | 1 - examples/programs/DKKpiTest.cxx | 1 - include/make_unique.h | 40 ---------------------- test/helperFunctions.h | 1 - test/test_DataSet.cxx | 1 - test/test_FourMomenta.cxx | 1 - test/test_FourMomentaCalculation.cxx | 1 - test/test_HelicityAngles.cxx | 1 - test/test_HelicityAngles_boostRotate.cxx | 1 - test/test_Model.cxx | 1 - test/test_swapDalitzAxes.cxx | 1 - test/test_swapFinalStates.cxx | 1 - 21 files changed, 60 deletions(-) delete mode 100644 include/make_unique.h diff --git a/examples/bat_gen/models/d3pi.h b/examples/bat_gen/models/d3pi.h index ec1dbfef..6e4d2586 100644 --- a/examples/bat_gen/models/d3pi.h +++ b/examples/bat_gen/models/d3pi.h @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/bat_gen/models/d4pi.h b/examples/bat_gen/models/d4pi.h index 66512787..b2167810 100644 --- a/examples/bat_gen/models/d4pi.h +++ b/examples/bat_gen/models/d4pi.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/bat_gen/models/dkkpi.h b/examples/bat_gen/models/dkkpi.h index b246f1a9..a53b0808 100644 --- a/examples/bat_gen/models/dkkpi.h +++ b/examples/bat_gen/models/dkkpi.h @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/bat_gen/runBatFit.cxx b/examples/bat_gen/runBatFit.cxx index bddbb6dd..4e8db0a8 100644 --- a/examples/bat_gen/runBatFit.cxx +++ b/examples/bat_gen/runBatFit.cxx @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/examples/bat_gen/runBatFitFitFractions.cxx b/examples/bat_gen/runBatFitFitFractions.cxx index 8613df70..b315b13b 100644 --- a/examples/bat_gen/runBatFitFitFractions.cxx +++ b/examples/bat_gen/runBatFitFitFractions.cxx @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/bat_gen/runBatGen.cxx b/examples/bat_gen/runBatGen.cxx index 031e7a03..409b68c8 100644 --- a/examples/bat_gen/runBatGen.cxx +++ b/examples/bat_gen/runBatGen.cxx @@ -10,7 +10,6 @@ #include #include -#include #include #include "bat_gen.h" diff --git a/examples/bat_gen/runFitFractions.cxx b/examples/bat_gen/runFitFractions.cxx index 91323cf8..f790a18c 100644 --- a/examples/bat_gen/runFitFractions.cxx +++ b/examples/bat_gen/runFitFractions.cxx @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/bat_gen/tools.h b/examples/bat_gen/tools.h index e5d0d5c0..7e30e9fd 100644 --- a/examples/bat_gen/tools.h +++ b/examples/bat_gen/tools.h @@ -2,7 +2,6 @@ #define __tools_h__ #include -#include #include #include diff --git a/examples/programs/D3piTest.cxx b/examples/programs/D3piTest.cxx index 1ebab763..88f07f80 100644 --- a/examples/programs/D3piTest.cxx +++ b/examples/programs/D3piTest.cxx @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/programs/D4piTest.cxx b/examples/programs/D4piTest.cxx index 7bd88630..2dd44aef 100644 --- a/examples/programs/D4piTest.cxx +++ b/examples/programs/D4piTest.cxx @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/examples/programs/DKKpiTest.cxx b/examples/programs/DKKpiTest.cxx index 6dab9c70..269d56f9 100644 --- a/examples/programs/DKKpiTest.cxx +++ b/examples/programs/DKKpiTest.cxx @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/include/make_unique.h b/include/make_unique.h deleted file mode 100644 index 83fc37bb..00000000 --- a/include/make_unique.h +++ /dev/null @@ -1,40 +0,0 @@ -/* YAP - Yet another PWA toolkit - Copyright 2015, Technische Universitaet Muenchen, - Authors: Daniel Greenwald, Johannes Rauch - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/// \file - -#ifndef yap_make_unique_h -#define yap_make_unique_h - -#include - -/// c++14 implements make_unique -/// for c++11 we have to define it ourselves -#if __cplusplus <= 201103L -namespace std { - -template -std::unique_ptr make_unique( Args&& ...args ) -{ - return std::unique_ptr( new T( std::forward(args)... ) ); -} - -} -#endif - -#endif diff --git a/test/helperFunctions.h b/test/helperFunctions.h index f1ff7abf..40bd32b0 100644 --- a/test/helperFunctions.h +++ b/test/helperFunctions.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/test/test_DataSet.cxx b/test/test_DataSet.cxx index 2f7753b6..bf065888 100644 --- a/test/test_DataSet.cxx +++ b/test/test_DataSet.cxx @@ -6,7 +6,6 @@ #include #include #include -#include #include TEST_CASE("DataSet") diff --git a/test/test_FourMomenta.cxx b/test/test_FourMomenta.cxx index c4fd58cd..0946210a 100644 --- a/test/test_FourMomenta.cxx +++ b/test/test_FourMomenta.cxx @@ -7,7 +7,6 @@ #include #include #include -#include #include #include diff --git a/test/test_FourMomentaCalculation.cxx b/test/test_FourMomentaCalculation.cxx index 15a418e1..de17418d 100644 --- a/test/test_FourMomentaCalculation.cxx +++ b/test/test_FourMomentaCalculation.cxx @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include diff --git a/test/test_HelicityAngles.cxx b/test/test_HelicityAngles.cxx index 3a9b5319..4e914598 100644 --- a/test/test_HelicityAngles.cxx +++ b/test/test_HelicityAngles.cxx @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/test/test_HelicityAngles_boostRotate.cxx b/test/test_HelicityAngles_boostRotate.cxx index 6f67f987..5a0dd77f 100644 --- a/test/test_HelicityAngles_boostRotate.cxx +++ b/test/test_HelicityAngles_boostRotate.cxx @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/test/test_Model.cxx b/test/test_Model.cxx index 0c00ecd4..b348f7cf 100644 --- a/test/test_Model.cxx +++ b/test/test_Model.cxx @@ -3,7 +3,6 @@ #include #include #include -#include #include #include diff --git a/test/test_swapDalitzAxes.cxx b/test/test_swapDalitzAxes.cxx index dfa9a0b4..77442e61 100644 --- a/test/test_swapDalitzAxes.cxx +++ b/test/test_swapDalitzAxes.cxx @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/test/test_swapFinalStates.cxx b/test/test_swapFinalStates.cxx index 03274c83..cfc45f84 100644 --- a/test/test_swapFinalStates.cxx +++ b/test/test_swapFinalStates.cxx @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include From f6cb4a40a86f40a535bda36b36df97f6331f5b36 Mon Sep 17 00:00:00 2001 From: Daniel Greenwald Date: Thu, 13 Apr 2017 17:14:43 +0200 Subject: [PATCH 3/4] constexpr on QuantumNumbers --- include/QuantumNumbers.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/QuantumNumbers.h b/include/QuantumNumbers.h index 5b3947e5..814d8e5d 100644 --- a/include/QuantumNumbers.h +++ b/include/QuantumNumbers.h @@ -40,7 +40,7 @@ class QuantumNumbers /// QJPICG constructor /// \todo restore constexpr if using c++14 - QuantumNumbers(int Q, unsigned twoJ, int P, unsigned twoI, int C, int G) + constexpr QuantumNumbers(int Q, unsigned twoJ, int P, unsigned twoI, int C, int G) : Q_(Q), TwoJ_(twoJ), P_(signum(P)), C_(signum(C)), TwoI_(twoI), G_(signum(G)) { if (Q_ != 0 and C_ != 0) @@ -49,7 +49,7 @@ class QuantumNumbers /// QJPI constructor constexpr QuantumNumbers(int Q, unsigned twoJ, int P = 0, unsigned twoI = 0) - : Q_(Q), TwoJ_(twoJ), P_(signum(P)), C_(0), TwoI_(twoI), G_(0) {} + : Q_(Q), TwoJ_(twoJ), P_(signum(P)), TwoI_(twoI) {} /// @} @@ -123,23 +123,23 @@ class QuantumNumbers int P_; /// C-parity - int C_; + int C_{0}; /// Isospin * 2 unsigned TwoI_; /// G-parity - int G_; + int G_{0}; }; /// equality operator -inline const bool operator==(const QuantumNumbers& lhs, const QuantumNumbers& rhs) +constexpr bool operator==(const QuantumNumbers& lhs, const QuantumNumbers& rhs) { return lhs.twoJ() == rhs.twoJ() and lhs.P() == rhs.P() and lhs.C() == rhs.C() and lhs.twoI() == rhs.twoI() and lhs.G() == rhs.G() and lhs.Q() == rhs.Q(); } /// inequality operator -inline const bool operator!=(const QuantumNumbers& lhs, const QuantumNumbers& rhs) +constexpr bool operator!=(const QuantumNumbers& lhs, const QuantumNumbers& rhs) { return !(lhs == rhs); } /// convert to string From ae2927eb31b887154b76ff93e4fc06371ee8b886 Mon Sep 17 00:00:00 2001 From: Daniel Greenwald Date: Thu, 13 Apr 2017 17:57:36 +0200 Subject: [PATCH 4/4] +lambda autos --- examples/programs/D3piTest.cxx | 4 ++-- include/CoordinateSystem.h | 7 +++---- include/Parameter.h | 6 ++---- include/Particle.h | 10 +++------- include/Spin.h | 13 ++++++------- include/container_utils.h | 11 +++++------ src/DataAccessor.cxx | 3 +-- src/DecayChannel.cxx | 4 ++-- src/DecayTree.cxx | 3 +-- src/DecayingParticle.cxx | 4 ++-- src/FourMomenta.cxx | 4 ++-- src/ImportanceSampler.cxx | 6 ++---- src/MassRange.cxx | 2 +- src/Model.cxx | 19 ++++++------------- src/ModelIntegral.cxx | 3 +-- src/Particle.cxx | 6 ++---- src/ParticleCombination.cxx | 6 ++---- src/ParticleTable.cxx | 3 +-- src/SpinAmplitude.cxx | 3 +-- src/ZemachFormalism.cxx | 2 +- test/test_integration.cxx | 4 +--- 21 files changed, 47 insertions(+), 76 deletions(-) diff --git a/examples/programs/D3piTest.cxx b/examples/programs/D3piTest.cxx index 88f07f80..231dc0aa 100644 --- a/examples/programs/D3piTest.cxx +++ b/examples/programs/D3piTest.cxx @@ -163,8 +163,8 @@ int main( int argc, char** argv) auto I = integrals(mci.Integral); for (const auto& row : I) LOG(INFO) << std::accumulate(row.begin(), row.end(), std::string(""), - [](std::string & s, const yap::ComplexIntegralElement & c) - { return s += "\t" + to_string(c);}).erase(0, 1); + [](std::string & s, const auto& c) + {return s += "\t" + to_string(c);}).erase(0, 1); } // LOG(INFO) << std::endl << "Fixed amplitudes: "; diff --git a/include/CoordinateSystem.h b/include/CoordinateSystem.h index 41d01803..daf235c1 100644 --- a/include/CoordinateSystem.h +++ b/include/CoordinateSystem.h @@ -40,8 +40,7 @@ template std::string to_string(const CoordinateSystem& C) { return "(" + std::accumulate(C.begin(), C.end(), std::string(""), - [](std::string& s, const typename CoordinateSystem::value_type& v) - { return s += ", " + to_string(v); }).erase(0, 2) + ")"; + [](auto& s, const auto& v){return s += ", " + to_string(v); }).erase(0, 2) + ")"; } /// \return CoordinateSystem with vectors of unit norm @@ -50,7 +49,7 @@ template const CoordinateSystem unit(const CoordinateSystem& C) { CoordinateSystem uC; - std::transform(C.begin(), C.end(), uC.begin(), [](const Vector& c) {return yap::unit(c);}); + std::transform(C.begin(), C.end(), uC.begin(), [](const auto& c){return yap::unit(c);}); return uC; } @@ -60,7 +59,7 @@ template const CoordinateSystem operator*(const SquareMatrix& M, const CoordinateSystem& C) { CoordinateSystem MC; - std::transform(C.begin(), C.end(), MC.begin(), [&](const Vector& c) {return M * c; }); + std::transform(C.begin(), C.end(), MC.begin(), [&](const auto& c){return M * c;}); return MC; } diff --git a/include/Parameter.h b/include/Parameter.h index 1f9832e9..944d6d3a 100644 --- a/include/Parameter.h +++ b/include/Parameter.h @@ -71,9 +71,7 @@ class ParameterBase template constexpr VariableStatus variable_status(IterType first, IterType last) { - return std::any_of(first, last, - [](const std::shared_ptr& p) - {return p->variableStatus() == VariableStatus::changed;}) + return std::any_of(first, last, [](const auto& p){return p->variableStatus() == VariableStatus::changed;}) ? VariableStatus::changed : VariableStatus::unchanged; } @@ -334,7 +332,7 @@ class ImaginaryComponentParameter : public ComplexComponentParameter /// \return number of real elements in ParameterVector inline const size_t size(const ParameterVector& V) -{ return std::accumulate(V.begin(), V.end(), size_t(0), [](size_t& s, const ParameterVector::value_type & p) {return s += p->size();}); } +{ return std::accumulate(V.begin(), V.end(), size_t(0), [](size_t& s, const auto& p){return s += p->size();}); } /// set values in ParameterVector from iterators template diff --git a/include/Particle.h b/include/Particle.h index d22f024a..e5b1c8fb 100644 --- a/include/Particle.h +++ b/include/Particle.h @@ -114,11 +114,11 @@ class Particle : public std::enable_shared_from_this /// \return charge of ParticleVector inline const int charge(const ParticleVector& P) -{ return std::accumulate(P.begin(), P.end(), 0, [](int q, const ParticleVector::value_type& p){return q + p->quantumNumbers().Q();}); } +{ return std::accumulate(P.begin(), P.end(), 0, [](int q, const auto& p){return q + p->quantumNumbers().Q();}); } /// \return parity of ParticleVector inline const int parity(const ParticleVector& P) -{ return std::accumulate(P.begin(), P.end(), 1, [](int q, const ParticleVector::value_type& p){return q * p->quantumNumbers().P();}); } +{ return std::accumulate(P.begin(), P.end(), 1, [](int q, const auto& p){return q * p->quantumNumbers().P();}); } /// \return SpinVector from ParticleVector const SpinVector spins(const ParticleVector& v); @@ -132,11 +132,7 @@ inline std::string to_string(const Particle& p) /// convert to string inline std::string to_string(const ParticleVector& p) -{ - return std::accumulate(p.begin(), p.end(), std::string(""), - [](std::string& s, const ParticleVector::value_type& p) - {return s += ", " + p->name();}).erase(0, 2); -} +{ return std::accumulate(p.begin(), p.end(), std::string(""), [](std::string& s, const auto& p){return s += ", " + p->name();}).erase(0, 2); } /// convert to string std::string to_string(const ParticleVector& p, const SpinProjectionVector& two_m); diff --git a/include/Spin.h b/include/Spin.h index 08e1306b..b11f2a93 100644 --- a/include/Spin.h +++ b/include/Spin.h @@ -40,16 +40,16 @@ inline std::string spin_to_string(int twoJ) inline std::string to_string(const SpinVector& two_j) { return std::accumulate(two_j.begin(), two_j.end(), std::string(""), - [](const std::string & s, const SpinVector::value_type & j) - {return s + " + " + spin_to_string(j);}).erase(0, 3); + [](const std::string & s, auto j) + {return s + " + " + spin_to_string(j);}).erase(0, 3); } /// convert SpinVector to string inline std::string to_string(const SpinProjectionVector& two_m) { return std::accumulate(two_m.begin(), two_m.end(), std::string(""), - [](const std::string & s, const SpinProjectionVector::value_type & m) - {return s + " + " + spin_to_string(m);}).erase(0, 3); + [](const std::string & s, auto m) + {return s + " + " + spin_to_string(m);}).erase(0, 3); } /// \return whether three spins fulfill the triangle relationship @@ -90,8 +90,7 @@ inline const std::vector projections(const SpinVector& two // initialize vector of spin projections to -two_j std::vector two_M; two_M.reserve(two_J.size()); - std::transform(two_J.begin(), two_J.end(), std::back_inserter(two_M), - [](const SpinVector::value_type & two_j) {return -two_j;}); + std::transform(two_J.begin(), two_J.end(), std::back_inserter(two_M), [](auto two_j){return -two_j;}); std::vector SPV; // fill SPV with "odometer"-style looping @@ -108,7 +107,7 @@ inline const std::vector projections(const SpinVector& two /// \return whether all spins are zero inline const bool all_zero(const SpinVector& two_J) -{ return std::all_of(two_J.begin(), two_J.end(), [](SpinVector::value_type two_j){return two_j == 0;}); } +{ return std::all_of(two_J.begin(), two_J.end(), [](auto two_j){return two_j == 0;}); } } diff --git a/include/container_utils.h b/include/container_utils.h index fac87152..882ac28b 100644 --- a/include/container_utils.h +++ b/include/container_utils.h @@ -30,7 +30,7 @@ bool overlap(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, B { using T1 = typename std::iterator_traits::value_type; using T2 = typename std::iterator_traits::value_type; - return std::any_of(first1, last1, [&](const T1 & a) { return std::any_of(first2, last2, [&](const T2 & b) {return p(a, b);}); }); + return std::any_of(first1, last1, [&](const T1& a) { return std::any_of(first2, last2, [&](const T2& b) {return p(a, b);}); }); } /// check if two containers are disjoint (no sorting necessary). @@ -40,7 +40,7 @@ bool disjoint(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, { using T1 = typename std::iterator_traits::value_type; using T2 = typename std::iterator_traits::value_type; - return std::none_of(first1, last1, [&](const T1 & a) { return std::none_of(first2, last2, [&](const T2 & b) {return p(a, b);}); }); + return std::none_of(first1, last1, [&](const T1& a) { return std::none_of(first2, last2, [&](const T2& b) {return p(a, b);}); }); } /// check if first container contains second (no sorting necessary). @@ -48,7 +48,7 @@ bool disjoint(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, template bool contains(InputIt1 first_haystack, InputIt1 last_haystack, InputIt2 first_needle, InputIt2 last_needle, BinaryPredicate p) { - return std::all_of(first_needle, last_needle, [&](const typename std::iterator_traits::value_type& b) + return std::all_of(first_needle, last_needle, [&](const auto& b) {return std::any_of(first_haystack, last_haystack, std::bind(p, std::placeholders::_1, b)); }); } @@ -57,8 +57,7 @@ bool contains(InputIt1 first_haystack, InputIt1 last_haystack, InputIt2 first_ne template const bool orderless_equal(InputIt first1, InputIt last1, InputIt first2, InputIt last2) { - return std::all_of(first1, last1, [&](const typename std::iterator_traits::value_type& a) - {return std::count(first1, last1, a) == std::count(first2, last2, a);}); + return std::all_of(first1, last1, [&](const auto& a){return std::count(first1, last1, a) == std::count(first2, last2, a);}); } /// equality comparison, checks that haystack contains needle @@ -66,7 +65,7 @@ const bool orderless_equal(InputIt first1, InputIt last1, InputIt first2, InputI template const bool orderless_contains(InputIt first_haystack, InputIt last_haystack, InputIt first_needle, InputIt last_needle) { - return std::all_of(first_needle, last_needle, [&](const typename std::iterator_traits::value_type& a) + return std::all_of(first_needle, last_needle, [&](const auto& a) {return std::count(first_needle, last_needle, a) <= std::count(first_haystack, last_haystack, a);}); } diff --git a/src/DataAccessor.cxx b/src/DataAccessor.cxx index f2acbb90..bcf2a3c4 100644 --- a/src/DataAccessor.cxx +++ b/src/DataAccessor.cxx @@ -40,8 +40,7 @@ void DataAccessor::addParticleCombination(const ParticleCombination& c) // search for match using Equal auto it = std::find_if(SymmetrizationIndices_.begin(), SymmetrizationIndices_.end(), - [&](const ParticleCombinationMap::value_type & kv) - {return Equal_(c.shared_from_this(), kv.first);}); + [&](const auto& kv){return Equal_(c.shared_from_this(), kv.first);}); // if found, use found index if (it != SymmetrizationIndices_.end()) { diff --git a/src/DecayChannel.cxx b/src/DecayChannel.cxx index 64e93b3c..1c8f9fbd 100644 --- a/src/DecayChannel.cxx +++ b/src/DecayChannel.cxx @@ -227,12 +227,12 @@ bool DecayChannel::consistent() const bool C = true; // check no daughters is empty - if (std::any_of(Daughters_.begin(), Daughters_.end(), [](std::shared_ptr d) {return !d;})) { + if (std::any_of(Daughters_.begin(), Daughters_.end(), [](auto d) {return !d;})) { FLOG(ERROR) << "null pointer in daughters vector."; C &= false; } // check daughters - std::for_each(Daughters_.begin(), Daughters_.end(), [&](std::shared_ptr d) {if (d) C &= d->consistent();}); + std::for_each(Daughters_.begin(), Daughters_.end(), [&](auto d) {if (d) C &= d->consistent();}); // loop over SpinAmplitude's for (const auto& sa : SpinAmplitudes_) { diff --git a/src/DecayTree.cxx b/src/DecayTree.cxx index 65ebc158..8b5a96db 100644 --- a/src/DecayTree.cxx +++ b/src/DecayTree.cxx @@ -177,8 +177,7 @@ std::string to_string(const DecayTree& dt, std::string offset) std::string to_string(const DecayTreeVector& dtv) { return std::accumulate(dtv.begin(), dtv.end(), std::string(), - [](std::string& s, const DecayTreeVector::value_type& dt) - { return s += "\n" + to_string(*dt); }).erase(0, 1); + [](auto& s, const auto& dt){return s += "\n" + to_string(*dt);}).erase(0, 1); } //------------------------- diff --git a/src/DecayingParticle.cxx b/src/DecayingParticle.cxx index c0aa2309..28c1fa15 100644 --- a/src/DecayingParticle.cxx +++ b/src/DecayingParticle.cxx @@ -58,7 +58,7 @@ bool DecayingParticle::consistent() const } // check consistency of all channels - std::for_each(DecayChannels_.begin(), DecayChannels_.end(), [&](const std::shared_ptr& dc) {if (dc) C &= dc->consistent();}); + std::for_each(DecayChannels_.begin(), DecayChannels_.end(), [&](const auto& dc){if (dc) C &= dc->consistent();}); if (MassShape_) { C &= MassShape_->consistent(); @@ -398,7 +398,7 @@ std::string to_decay_string(const DecayingParticle& dp, unsigned level) s += pad_right(to_string(c->spinAmplitudes()), sa_padding); - for (const auto& d : filter(c->daughters(), [](const std::shared_ptr& p){return p and is_decaying_particle(*p);})) + for (const auto& d : filter(c->daughters(), [](const auto& p){return p and is_decaying_particle(*p);})) s += ", " + to_decay_string(static_cast(*d), level + 1); } diff --git a/src/FourMomenta.cxx b/src/FourMomenta.cxx index cabb1dc8..6dc4b3a9 100644 --- a/src/FourMomenta.cxx +++ b/src/FourMomenta.cxx @@ -115,7 +115,7 @@ void FourMomenta::calculate(DataPoint& d, StatusManager& sm) const continue; const auto P = std::accumulate(kv.first->indices().begin(), kv.first->indices().end(), FourVector(), - [&](const FourVector& V, unsigned i) {return V + fsp[i];}); + [&](const auto& V, unsigned i) {return V + fsp[i];}); P_->setValue(P, d, kv.second, sm); M_->setValue(abs(P), d, kv.second, sm); @@ -186,7 +186,7 @@ std::string FourMomenta::massesString(const DataPoint& d, unsigned m_p) const bool check_invariant_masses(const MassAxes& axes, const std::vector& squared_masses, const std::vector >& fourMomenta) { for (size_t i = 0; i < axes.size(); ++i) { - auto p = std::accumulate(axes[i]->indices().begin(), axes[i]->indices().end(), FourVector(), [&](const FourVector& p, unsigned j) {return p + fourMomenta[j];}); + auto p = std::accumulate(axes[i]->indices().begin(), axes[i]->indices().end(), FourVector(), [&](const auto& p, unsigned j){return p + fourMomenta[j];}); if (fabs(norm(p) - squared_masses[i]) > 5. * std::numeric_limits::epsilon() ) return false; } diff --git a/src/ImportanceSampler.cxx b/src/ImportanceSampler.cxx index dba893d4..31d51510 100644 --- a/src/ImportanceSampler.cxx +++ b/src/ImportanceSampler.cxx @@ -25,8 +25,7 @@ void ImportanceSampler::calculate(std::vector >& A, const D if (I.decayTrees().size() != A.size()) throw exceptions::Exception("size mismatch", "calculate"); // calculate the amplitudes of all decay trees - std::transform(I.decayTrees().begin(), I.decayTrees().end(), A.begin(), - [&d](const std::shared_ptr& dt) {return dt->dataDependentAmplitude(d);}); + std::transform(I.decayTrees().begin(), I.decayTrees().end(), A.begin(), [&d](const auto& dt) {return dt->dataDependentAmplitude(d);}); } //------------------------- @@ -153,8 +152,7 @@ unsigned ImportanceSampler::calculate_subset(std::vector > > A; std::transform(J.begin(), J.end(), std::back_inserter(A), - [](const DecayTreeVectorIntegral* j) - {return std::vector >(j->decayTrees().size());}); + [](const auto j){return std::vector >(j->decayTrees().size());}); // create DataSet and DataPoint auto data = const_cast(J[0]->model())->createDataSet(); diff --git a/src/MassRange.cxx b/src/MassRange.cxx index e6086f70..e07bfe72 100644 --- a/src/MassRange.cxx +++ b/src/MassRange.cxx @@ -41,7 +41,7 @@ const std::vector mass_range(double isp_mass, const MassAxes& A, cons { std::vector R; R.reserve(A.size()); - std::transform(A.begin(), A.end(), std::back_inserter(R), [&](const MassAxes::value_type & a) {return mass_range(isp_mass, a, FSPs);}); + std::transform(A.begin(), A.end(), std::back_inserter(R), [&](const auto& a){return mass_range(isp_mass, a, FSPs);}); return R; } diff --git a/src/Model.cxx b/src/Model.cxx index 7f070267..af353f5b 100644 --- a/src/Model.cxx +++ b/src/Model.cxx @@ -81,9 +81,7 @@ const double intensity(const ModelComponent& c, const DataPoint& d) //------------------------- const double intensity(const std::vector& C, const DataPoint& d) { - return std::accumulate(C.begin(), C.end(), 0., - [&d](double& I, const ModelComponent& c) - {return I += intensity(c, d);}); + return std::accumulate(C.begin(), C.end(), 0., [&d](double I, const auto& c) {return I + intensity(c, d);}); } //------------------------- @@ -97,12 +95,10 @@ const double sum_of_logs_of_intensities(const Model& M, DataPartition& D, double // if pedestal is zero if (ped == 0) return std::accumulate(D.begin(), D.end(), CompensatedSum(0.), - [&](CompensatedSum& l, const DataPoint& d) - {return l += log(intensity(M, d));}); + [&](auto& l, const auto& d){return l += log(intensity(M, d));}); // else return std::accumulate(D.begin(), D.end(), CompensatedSum(0.), - [&](CompensatedSum& l, const DataPoint& d) - {return l += (log(intensity(M, d)) - ped);}); + [&](auto& l, const auto& d){return l += (log(intensity(M, d)) - ped);}); } //------------------------- @@ -141,8 +137,7 @@ const double sum_of_log_intensity(const Model& M, DataPartitionVector& DP, doubl partial_sums.push_back(std::async(std::launch::async, sum_of_logs_of_intensities, std::cref(M), std::ref(*P), ped)); // wait for each partition to finish calculating - return std::accumulate(partial_sums.begin(), partial_sums.end(), 0., - [](double& l, std::future& s) {return l += s.get();}); + return std::accumulate(partial_sums.begin(), partial_sums.end(), 0., [](auto l, auto& s) {return l + s.get();}); } //------------------------- @@ -249,9 +244,7 @@ void Model::addInitialState(DecayingParticle& p) //------------------------- size_t all_fixed(const std::vector& C) { - return std::all_of(C.begin(), C.end(), - [](const ModelComponent& c) - {return c.admixture()->variableStatus() == VariableStatus::fixed;}); + return std::all_of(C.begin(), C.end(), [](const auto& c){return c.admixture()->variableStatus() == VariableStatus::fixed;}); } //------------------------- @@ -383,7 +376,7 @@ const MassAxes Model::massAxes(std::vector > pcs) // for the moment, we only support 2-particle axes // check that all axes are 2 -particle - if (std::any_of(pcs.begin(), pcs.end(), [](const std::vector& v) {return v.size() != 2;})) + if (std::any_of(pcs.begin(), pcs.end(), [](const auto& v) {return v.size() != 2;})) throw exceptions::Exception("only 2-particle axes supported currently", "Model::massAxes"); ParticleCombinationVector M; diff --git a/src/ModelIntegral.cxx b/src/ModelIntegral.cxx index 358ddc94..f1096271 100644 --- a/src/ModelIntegral.cxx +++ b/src/ModelIntegral.cxx @@ -29,8 +29,7 @@ ModelIntegral::ModelIntegral(const Model& model) const RealIntegralElement integral(const ModelIntegral& MI) { return std::accumulate(MI.integrals().begin(), MI.integrals().end(), RealIntegralElement(), - [](RealIntegralElement& I, const ModelComponentIntegral& mci) - { return I += mci.Admixture->value() * integral(mci.Integral); }); + [](auto& I, const auto& mci){return I += mci.Admixture->value() * integral(mci.Integral);}); } } diff --git a/src/Particle.cxx b/src/Particle.cxx index e2b32e3b..d958f366 100644 --- a/src/Particle.cxx +++ b/src/Particle.cxx @@ -37,8 +37,7 @@ const SpinVector spins(const ParticleVector& v) { SpinVector s; s.reserve(v.size()); - std::transform(v.begin(), v.end(), std::back_inserter(s), - [](const ParticleVector::value_type & p) {return p->quantumNumbers().twoJ();}); + std::transform(v.begin(), v.end(), std::back_inserter(s), [](const auto& p){return p->quantumNumbers().twoJ();}); return s; } @@ -46,8 +45,7 @@ const SpinVector spins(const ParticleVector& v) const bool decays_to_full_final_state(const Particle& p) { return std::any_of(p.particleCombinations().begin(), p.particleCombinations().end(), - [&p](const ParticleCombinationSet::value_type& pc) - {return pc->indices().size() == p.model()->finalStateParticles().size();}); + [&p](const auto& pc){return pc->indices().size() == p.model()->finalStateParticles().size();}); } //------------------------- diff --git a/src/ParticleCombination.cxx b/src/ParticleCombination.cxx index 1518c2bb..c267e805 100644 --- a/src/ParticleCombination.cxx +++ b/src/ParticleCombination.cxx @@ -63,16 +63,14 @@ bool ParticleCombination::consistent() const } // count number of daughters with parent not set to this - auto n = std::count_if(Daughters_.begin(), Daughters_.end(), - [&](const ParticleCombinationVector::value_type & d) {return d->parent().get() != this;}); + auto n = std::count_if(Daughters_.begin(), Daughters_.end(), [&](const auto& d){return d->parent().get() != this;}); if (n != 0) { FLOG(ERROR) << n << " daughters' parent not set to this ParticleCombination."; C &= false; } // check consistency of daughters - std::for_each(Daughters_.begin(), Daughters_.end(), - [&](const ParticleCombinationVector::value_type & d) {C &= d->consistent();}); + std::for_each(Daughters_.begin(), Daughters_.end(), [&](const auto& d) {C &= d->consistent();}); } // if Daugthers_ empty, should have one and only index (as FSP) else if (Indices_.size() != 1) { diff --git a/src/ParticleTable.cxx b/src/ParticleTable.cxx index b46c8f8f..6c04f5b8 100644 --- a/src/ParticleTable.cxx +++ b/src/ParticleTable.cxx @@ -54,8 +54,7 @@ const ParticleTableEntry& ParticleTable::operator[](int PDG) const //------------------------- const ParticleTableEntry& ParticleTable::operator[](const std::string& name) const { - auto it = std::find_if(ParticleTableMap_.begin(), ParticleTableMap_.end(), - [&](const std::map::value_type & p) {return p.second.name() == name;}); + auto it = std::find_if(ParticleTableMap_.begin(), ParticleTableMap_.end(), [&](const auto& p){return p.second.name() == name;}); if (it == ParticleTableMap_.end()) throw exceptions::Exception("particle with name \"" + name + "\" not found", "ParticleTable::operator[]"); return it->second; diff --git a/src/SpinAmplitude.cxx b/src/SpinAmplitude.cxx index 2b0fd70f..cdf9d800 100644 --- a/src/SpinAmplitude.cxx +++ b/src/SpinAmplitude.cxx @@ -76,8 +76,7 @@ const std::set SpinAmplitude::twoM(int two_M) const return std::set(); std::set two_m; - std::transform(it->second.begin(), it->second.end(), std::inserter(two_m, two_m.end()), - [](const AmplitudeSubmap::value_type & kv) {return kv.first;}); + std::transform(it->second.begin(), it->second.end(), std::inserter(two_m, two_m.end()), [](const auto& kv) {return kv.first;}); return two_m; } diff --git a/src/ZemachFormalism.cxx b/src/ZemachFormalism.cxx index c4a8ba81..8c635531 100644 --- a/src/ZemachFormalism.cxx +++ b/src/ZemachFormalism.cxx @@ -80,7 +80,7 @@ ZemachSpinAmplitude::ZemachSpinAmplitude(Model& m, unsigned two_J, const SpinVec "ZemachSpinAmplitude::ZemachSpinAmplitude"); } else { - if (std::all_of(finalTwoJ().begin(), finalTwoJ().end(), [](const SpinVector::value_type & j) {return j != 0;})) + if (std::all_of(finalTwoJ().begin(), finalTwoJ().end(), [](const auto& j) {return j != 0;})) throw exceptions::Exception("one daughter must be a scalar", "ZemachSpinAmplitude::ZemachSpinAmplitude"); // get resonance spin diff --git a/test/test_integration.cxx b/test/test_integration.cxx index edb95387..eb62adac 100644 --- a/test/test_integration.cxx +++ b/test/test_integration.cxx @@ -47,9 +47,7 @@ TEST_CASE("integration") partial_sums.push_back(std::async(std::launch::async, sum_of_intensities, std::ref(*P))); // wait for each partition to finish calculating - double bruteForceIntegral = std::accumulate(partial_sums.begin(), partial_sums.end(), 0., - [](double & l, std::future& s) - {return l += s.get();}); + double bruteForceIntegral = std::accumulate(partial_sums.begin(), partial_sums.end(), 0., [](double l, auto& s){return l + s.get();}); DEBUG("bruteForceIntegral = " << bruteForceIntegral);