Skip to content

Switch to C++14 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/models/d3pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <FinalStateParticle.h>
#include <Flatte.h>
#include <FreeAmplitude.h>
#include <make_unique.h>
#include <MathUtilities.h>
#include <Model.h>
#include <Parameter.h>
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/models/d4pi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <FreeAmplitude.h>
#include <HelicityFormalism.h>
#include <logging.h>
#include <make_unique.h>
#include <MathUtilities.h>
#include <Model.h>
#include <Parameter.h>
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/models/dkkpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <BreitWigner.h>
#include <DecayingParticle.h>
#include <FinalStateParticle.h>
#include <make_unique.h>
#include <MathUtilities.h>
#include <Model.h>
#include <ParticleCombination.h>
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/runBatFit.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <RelativisticBreitWigner.h>
#include <ZemachFormalism.h>
#include <logging.h>
#include <make_unique.h>

#include <BAT/BCAux.h>
#include <BAT/BCLog.h>
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/runBatFitFitFractions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <DecayTree.h>
#include <HelicityFormalism.h>
#include <logging.h>
#include <make_unique.h>
#include <MassRange.h>
#include <Model.h>
#include <PHSP.h>
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/runBatGen.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <HelicityFormalism.h>
#include <logging.h>
#include <make_unique.h>
#include <ZemachFormalism.h>

#include "bat_gen.h"
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/runFitFractions.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <HelicityFormalism.h>
#include <ImportanceSampler.h>
#include <logging.h>
#include <make_unique.h>
#include <MassRange.h>
#include <PHSP.h>
#include <ZemachFormalism.h>
Expand Down
1 change: 0 additions & 1 deletion examples/bat_gen/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define __tools_h__

#include <FourVector.h>
#include <make_unique.h>
#include <Model.h>

#include <TLorentzVector.h>
Expand Down
5 changes: 2 additions & 3 deletions examples/programs/D3piTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include <HelicityFormalism.h>
#include <ImportanceSampler.h>
#include <logging.h>
#include <make_unique.h>
#include <MassAxes.h>
#include <MassRange.h>
#include <Model.h>
Expand Down Expand Up @@ -164,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: ";
Expand Down
1 change: 0 additions & 1 deletion examples/programs/D4piTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <HelicityAngles.h>
#include <HelicityFormalism.h>
#include <logging.h>
#include <make_unique.h>
#include <MassAxes.h>
#include <MassShapeWithNominalMass.h>
#include <Model.h>
Expand Down
1 change: 0 additions & 1 deletion examples/programs/DKKpiTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <FourVector.h>
#include <HelicityAngles.h>
#include <HelicityFormalism.h>
#include <make_unique.h>
#include <MassAxes.h>
#include <Model.h>
#include <Parameter.h>
Expand Down
7 changes: 3 additions & 4 deletions include/CoordinateSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ template <typename T, size_t N>
std::string to_string(const CoordinateSystem<T, N>& C)
{
return "(" + std::accumulate(C.begin(), C.end(), std::string(""),
[](std::string& s, const typename CoordinateSystem<T, N>::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
Expand All @@ -50,7 +49,7 @@ template <typename T, size_t N>
const CoordinateSystem<T, N> unit(const CoordinateSystem<T, N>& C)
{
CoordinateSystem<T, N> uC;
std::transform(C.begin(), C.end(), uC.begin(), [](const Vector<T, N>& c) {return yap::unit<T, N>(c);});
std::transform(C.begin(), C.end(), uC.begin(), [](const auto& c){return yap::unit<T, N>(c);});
return uC;
}

Expand All @@ -60,7 +59,7 @@ template <typename T, size_t N>
const CoordinateSystem<T, N> operator*(const SquareMatrix<T, N>& M, const CoordinateSystem<T, N>& C)
{
CoordinateSystem<T, N> MC;
std::transform(C.begin(), C.end(), MC.begin(), [&](const Vector<T, N>& c) {return M * c; });
std::transform(C.begin(), C.end(), MC.begin(), [&](const auto& c){return M * c;});
return MC;
}

Expand Down
6 changes: 2 additions & 4 deletions include/Parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ class ParameterBase
template <typename IterType>
constexpr VariableStatus variable_status(IterType first, IterType last)
{
return std::any_of(first, last,
[](const std::shared_ptr<ParameterBase>& p)
{return p->variableStatus() == VariableStatus::changed;})
return std::any_of(first, last, [](const auto& p){return p->variableStatus() == VariableStatus::changed;})
? VariableStatus::changed : VariableStatus::unchanged;
}

Expand Down Expand Up @@ -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 <class InputIt>
Expand Down
10 changes: 3 additions & 7 deletions include/Particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ class Particle : public std::enable_shared_from_this<Particle>

/// \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);
Expand All @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions include/QuantumNumbers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {}

/// @}

Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions include/Spin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,8 +90,7 @@ inline const std::vector<SpinProjectionVector> projections(const SpinVector& two
// initialize vector of spin projections to -two_j
std::vector<int> 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<SpinProjectionVector> SPV;
// fill SPV with "odometer"-style looping
Expand All @@ -108,7 +107,7 @@ inline const std::vector<SpinProjectionVector> 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;}); }

}

Expand Down
11 changes: 5 additions & 6 deletions include/container_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bool overlap(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, B
{
using T1 = typename std::iterator_traits<InputIt1>::value_type;
using T2 = typename std::iterator_traits<InputIt2>::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).
Expand All @@ -40,15 +40,15 @@ bool disjoint(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2,
{
using T1 = typename std::iterator_traits<InputIt1>::value_type;
using T2 = typename std::iterator_traits<InputIt2>::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).
/// BinaryPredicate must have signature bool(const InputIt1::type&, const InputIt2::type&)
template <class InputIt1, class InputIt2, class BinaryPredicate>
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<InputIt2>::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)); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std::bind can be replaced by a lambda:

{ return std::any_of(first_haystack, last_haystack, [&](const auto& a) { return p(a, b); }); });

}

Expand All @@ -57,16 +57,15 @@ bool contains(InputIt1 first_haystack, InputIt1 last_haystack, InputIt2 first_ne
template <class InputIt>
const bool orderless_equal(InputIt first1, InputIt last1, InputIt first2, InputIt last2)
{
return std::all_of(first1, last1, [&](const typename std::iterator_traits<InputIt>::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
/// doesn't care about order
template <class InputIt>
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<InputIt>::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);});
}

Expand Down
40 changes: 0 additions & 40 deletions include/make_unique.h

This file was deleted.

3 changes: 1 addition & 2 deletions src/DataAccessor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned>::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()) {
Expand Down
4 changes: 2 additions & 2 deletions src/DecayChannel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Particle> d) {return !d;})) {
if (std::any_of(Daughters_.begin(), Daughters_.end(), [](auto d) {return !d;})) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying a shared_ptr is expensive, I'd pass it by const reference.

FLOG(ERROR) << "null pointer in daughters vector.";
C &= false;
}
// check daughters
std::for_each(Daughters_.begin(), Daughters_.end(), [&](std::shared_ptr<Particle> 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_) {
Expand Down
3 changes: 1 addition & 2 deletions src/DecayTree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

//-------------------------
Expand Down
Loading