diff --git a/.gitignore b/.gitignore index 4bfb6b1b1..9d56fc628 100644 --- a/.gitignore +++ b/.gitignore @@ -1,31 +1,31 @@ build* .dir-locals.el TAGS third-party/*/ !third-party/cmake/* -!third-party/akantu-iterators +!third-party/akantu_iterators !third-party/iohelper *~ release .*.swp *.tar.gz *.tgz *.tbz *.tar.bz2 .idea __pycache__ .mailmap paraview/* *.vtu *.pvd *.pvtu *.vtk compile_commands.json .clangd .iwyu.imp .cache setup.cfg .vscode .auctex* .clangd .ccls-cache diff --git a/third-party/akantu_iterators/include/aka_named_tuple.hh b/third-party/akantu_iterators/include/aka_named_tuple.hh new file mode 100644 index 000000000..c04075d7f --- /dev/null +++ b/third-party/akantu_iterators/include/aka_named_tuple.hh @@ -0,0 +1,275 @@ +/** + * @file aka_tuple_tools.hh + * + * @author Nicolas Richart + * + * @date creation: Fri Aug 11 2017 + * @date last modification: Mon Jan 29 2018 + * + * @brief iterator interfaces + * + * + * Copyright 2019 EPFL (Ecole Polytechnique Fédérale de Lausanne) + * Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides) + * + * Akantu is free software: you can 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 3 of the License, or (at your option) any + * later version. + * + * Akantu 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 Lesser General Public License for more + * details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Akantu. If not, see . + * + */ + +/* -------------------------------------------------------------------------- */ +#include "aka_compatibilty_with_cpp_standard.hh" +#include "aka_str_hash.hh" +/* -------------------------------------------------------------------------- */ +#include +/* -------------------------------------------------------------------------- */ + +#ifndef AKANTU_AKA_NAMED_TUPLE_HH +#define AKANTU_AKA_NAMED_TUPLE_HH + +#ifndef AKANTU_ITERATORS_NAMESPACE +#define AKANTU_ITERATORS_NAMESPACE akantu +#endif + +namespace AKANTU_ITERATORS_NAMESPACE { + +namespace tuple { + using hash_type = uint64_t; + + /* ------------------------------------------------------------------------ */ + template struct named_tag { + using _tag = tag; ///< key + using _type = type; ///< value type + + template < + typename T, + std::enable_if_t::value> * = nullptr> + named_tag(T && value) // NOLINT + : _value(std::forward(value)) {} + + type _value; + }; + + namespace details { +/* -------------------------------------------------------------------------- */ +#if (defined(__GNUC__) || defined(__GNUG__)) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Weffc++" +#endif + template struct named_tag_proxy { + using _tag = tag; + + template auto operator=(T && value) -> decltype(auto) { + return named_tag<_tag, T>{std::forward(value)}; + } + }; +#if (defined(__GNUC__) || defined(__GNUG__)) +#pragma GCC diagnostic pop +#endif + } // namespace details + + /* ------------------------------------------------------------------------ */ + template struct is_named_tag : public std::false_type {}; + template + struct is_named_tag> : public std::true_type {}; + template + struct is_named_tag> : public std::true_type {}; + /* ------------------------------------------------------------------------ */ + + template + struct named_tuple : public std::tuple { + using Names_t = std::tuple; + using parent = std::tuple; + + named_tuple(Params &&... params) + : parent(std::forward(params._value)...) {} + + named_tuple(typename Params::_type &&... args) + : parent(std::forward(args)...) {} + + private: + template * = nullptr> + static constexpr auto get_element_index_() noexcept -> std::size_t { + return -1; + } + + template * = nullptr> + static constexpr auto get_element_index_() noexcept -> std::size_t { + using _tag = std::tuple_element_t; + return (std::is_same<_tag, tag>::value) + ? Idx + : get_element_index_(); + } + + public: + template + static constexpr auto get_element_index() noexcept -> std::size_t { + return get_element_index_(); + } + + template + static constexpr auto get_element_index(NT && /*unused*/) noexcept + -> std::size_t { + return get_element_index_(); + } + + template ::value> * = nullptr> + constexpr auto get(NT && /*unused*/) noexcept -> decltype(auto) { + const auto index = get_element_index(); + static_assert((index != std::size_t(-1)), "wrong named_tag"); + return (std::get(*this)); + } + + template ::value> * = nullptr> + constexpr auto get(NT && /*unused*/) const noexcept -> decltype(auto) { + const auto index = get_element_index(); + static_assert((index != std::size_t(-1)), "wrong named_tag"); + return (std::get(*this)); + } + + template ::value> * = nullptr> + constexpr auto has(NT && /*unused*/) const noexcept -> bool { + const auto index = get_element_index(); + return (index != std::size_t(-1)); + } + + template ::value> * = nullptr> + static constexpr auto has() noexcept -> bool { + constexpr auto index = get_element_index(); + return (index != std::size_t(-1)); + } + + template static constexpr auto has() noexcept -> bool { + constexpr auto index = + get_element_index_, 0>(); + return (index != std::size_t(-1)); + } + }; + + /* ---------------------------------------------------------------------- */ + template struct is_named_tuple : public std::false_type {}; + template + struct is_named_tuple> : public std::true_type {}; + /* ---------------------------------------------------------------------- */ + + template + constexpr auto make_named_tuple(Params &&... params) noexcept + -> decltype(auto) { + return named_tuple(std::forward(params)...); + } + + template + constexpr auto make_named_tag() noexcept -> decltype(auto) { + return details::named_tag_proxy{}; + } + + template constexpr auto get() -> decltype(auto) { + return make_named_tag>(); + } + + template + constexpr auto get(Tuple && tuple) -> decltype(auto) { + return tuple.get(get()); + } + + template struct has_helper { + using type = + aka::bool_constant::template has()>; + }; + + template + using has_t = typename has_helper::type; + + template + constexpr auto has(Tuple && /*tuple*/) -> bool { + return has_t::value; + } + + template constexpr auto has() -> bool { + return has_t::value; + } + + template ::value> * = nullptr> + constexpr auto get(Tuple && tuple) noexcept -> decltype(auto) { + return tuple.template get(); + } + + template struct tuple_name_tag { + using type = std::decay_t< + std::tuple_element_t::Names_t>>; + }; + + template + using tuple_name_tag_t = typename tuple_name_tag::type; + + template struct tuple_element { + using type = std::tuple_element_t; + }; + + template + using tuple_element_t = typename tuple_element::type; + +#if defined(__INTEL_COMPILER) +// intel warnings here +#elif defined(__clang__) +// clang warnings here +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wgnu-string-literal-operator-template" +#elif (defined(__GNUC__) || defined(__GNUG__)) +// gcc warnings here +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#endif + /// this is a GNU exstension + /// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3599.html + template + constexpr auto operator"" _n() -> decltype(auto) { + return make_named_tag::hash>>(); + } +#if defined(__clang__) +#pragma clang diagnostic pop +#elif (defined(__GNUC__) || defined(__GNUG__)) +#pragma GCC diagnostic pop +#endif + +} // namespace tuple + +} // namespace AKANTU_ITERATORS_NAMESPACE + +namespace aka { +template +struct size_type> { + using type = typename std::decay_t::size_type; +}; +} // namespace aka + +/* -------------------------------------------------------------------------- */ +#include +/* -------------------------------------------------------------------------- */ + +namespace std { +template +struct iterator_traits< + ::AKANTU_ITERATORS_NAMESPACE::tuple::named_tag> + : public iterator_traits {}; +} // namespace std + +#endif /* AKANTU_AKA_NAMED_TUPLE_HH */