Skip to content
Snippets Groups Projects

Implementations for geometryInInside() and geometryInOutside()

Merged lh1887 requested to merge feature/geometryInInOutside_rebase into master
Files
3
@@ -70,7 +70,6 @@ namespace Impl {
template<typename Tp>
struct TypeStorage_<Tp, false> {
TypeStorage_(Tp t) {
//tp_ = ::new Tp(t);
::new (&tp_) Tp(t);
}
@@ -106,18 +105,6 @@ namespace Impl {
constexpr variant_union_(std::integral_constant<size_t, N>, Args&&... args) :
tail_(std::integral_constant<size_t, N-1>(), std::forward<Args...>(args)...) {}
// TODO: This should not be a copy! However, if I return by reference,
// compiler tells me it can not return an temporary as a non-const ref. (which is of course
// true, but I don't see why this is a temporary?). Then again, one does not need this
// function anyway. Probably one should just drop it.
template<typename Tp>
auto getByType() {
return Dune::Hybrid::ifElse(std::is_same<Tp, Head_>(),
[this](auto) { return this->head_.get();},
[this](auto id) { return id(this->tail_).template getByType<Tp>();}
);
}
auto& getByIndex(std::integral_constant<size_t, 0>) {
return head_.get();
}
@@ -171,21 +158,65 @@ namespace Impl {
template<typename Tp>
auto& get() {
constexpr size_t idx = index_in_pack<Tp, T...>::value;
if (index_ != idx)
DUNE_THROW(Dune::Exception, "Bad variant access.");
return get<idx>();
}
template<typename Tp>
const auto& get() const {
constexpr size_t idx = index_in_pack<Tp, T...>::value;
if (index_ != idx)
DUNE_THROW(Dune::Exception, "Bad variant access.");
return get<idx>();
}
template<typename Tp>
Tp* get_if() {
if (not holds_alternative<Tp>())
return (Tp*) nullptr;
else
return &(get<Tp>());
}
template<typename Tp>
const Tp* get_if() const {
if (not holds_alternative<Tp>())
return (Tp*) nullptr;
else
return &(get<Tp>());
}
template<size_t N>
auto* get_if() {
using Tp = std::decay_t<decltype(get<N>())>;
if (not holds_alternative<N>())
return (Tp*) nullptr;
else
return &(get<Tp>());
}
template<size_t N>
const auto* get_if() const {
using Tp = std::decay_t<decltype(get<N>())>;
if (not holds_alternative<N>())
return (Tp*) nullptr;
else
return &(get<Tp>());
}
template<size_t N>
auto& get() {
if (index_ != N)
DUNE_THROW(Dune::Exception, "Bad variant access.");
return unions_.template getByIndex(std::integral_constant<size_t, N>());
}
template<size_t N>
const auto& get() const {
if (index_ != N)
DUNE_THROW(Dune::Exception, "Bad variant access.");
return unions_.template getByIndex(std::integral_constant<size_t, N>());
}
@@ -197,7 +228,7 @@ namespace Impl {
return unions_.getByIndex(std::integral_constant<size_t,index>());
}
constexpr std::size_t index() const {
constexpr std::size_t index() const noexcept {
return index_;
}
@@ -271,6 +302,14 @@ namespace Impl {
return (index_in_pack<Tp, T...>::value == index_);
}
/** \brief Check if a given type is the one that is currently active in the variant. */
template<size_t N>
constexpr bool holds_alternative() const {
// I have no idea how this could be really constexpr, but for STL-conformity,
// I'll leave the modifier there.
return (N == index_);
}
private:
variant_union_<T...> unions_;
std::size_t index_;
@@ -313,6 +352,26 @@ namespace Impl {
return var.template get<Tp>();
}
template<typename Tp, typename ...T>
const auto* get_if(const variant<T...>& var) {
return var.template get_if<Tp>();
}
template<typename Tp, typename ...T>
auto* get_if(variant<T...>& var) {
return var.template get_if<Tp>();
}
template<size_t N, typename ...T>
const auto* get_if(const variant<T...>& var) {
return var.template get_if<N>();
}
template<size_t N, typename ...T>
auto* get_if(variant<T...>& var) {
return var.template get_if<N>();
}
template<typename Tp, typename ...T>
constexpr bool holds_alternative(const variant<T...>& var) {
return var.template holds_alternative<Tp>();
Loading