From: Daniel Arndt Date: Sun, 30 Jul 2017 22:13:09 +0000 (+0200) Subject: Implement constexpr max and min for DEAL_II_WITH_CXX14=false X-Git-Tag: v9.0.0-rc1~1375^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4675%2Fhead;p=dealii.git Implement constexpr max and min for DEAL_II_WITH_CXX14=false --- diff --git a/include/deal.II/base/patterns.h b/include/deal.II/base/patterns.h index c5d0c4e015..69c8441b14 100644 --- a/include/deal.II/base/patterns.h +++ b/include/deal.II/base/patterns.h @@ -24,7 +24,7 @@ #include #include #include - +#include #include #include @@ -1270,12 +1270,12 @@ namespace Patterns struct RankInfo::value>::type> { static constexpr int list_rank = - std::max(internal::RankInfo::list_rank, - RankInfo::list_rank) + + std_cxx14::max(internal::RankInfo::list_rank, + RankInfo::list_rank) + 1; static constexpr int map_rank = - std::max(internal::RankInfo::map_rank, - RankInfo::map_rank) + + std_cxx14::max(internal::RankInfo::map_rank, + RankInfo::map_rank) + 1; }; diff --git a/include/deal.II/base/std_cxx14/algorithm.h b/include/deal.II/base/std_cxx14/algorithm.h new file mode 100644 index 0000000000..a644f32d45 --- /dev/null +++ b/include/deal.II/base/std_cxx14/algorithm.h @@ -0,0 +1,60 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- +#ifndef dealii__cxx14_algorithm_h +#define dealii__cxx14_algorithm_h + +#include + +#ifdef DEAL_II_WITH_CXX14 +#include +#endif + +DEAL_II_NAMESPACE_OPEN +namespace std_cxx14 +{ +#ifdef DEAL_II_WITH_CXX14 + using std::max; + using std::min; +#else + + template + constexpr const T &max(const T &a, const T &b) + { + return (a < b) ? b : a; + } + + template + constexpr const T &max(const T &a, const T &b, Compare comp) + { + return (comp(a, b)) ? b : a; + } + + template + constexpr const T &min(const T &a, const T &b) + { + return (b < a) ? b : a; + } + + template + constexpr const T &min(const T &a, const T &b, Compare comp) + { + return (comp(b, a)) ? b : a; + } + +#endif +} +DEAL_II_NAMESPACE_CLOSE + +#endif // dealii__cxx14_algorithm_h diff --git a/tests/base/stdcxx14_constexpr_min_max.cc b/tests/base/stdcxx14_constexpr_min_max.cc new file mode 100644 index 0000000000..0eb37376c2 --- /dev/null +++ b/tests/base/stdcxx14_constexpr_min_max.cc @@ -0,0 +1,51 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// test the implementation of theh constexpr min/max functions +// in case deal.II is compiled with C++14 support, we only test +// the STL. + + +#include "../tests.h" +#include +#include +#include +#include + +constexpr bool comp (const int &a, const int &b) +{ + return b