Skip to content

Commit

Permalink
std::move, std::forward -> const_expr::move, const_expr::forward
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Mosimann committed Apr 25, 2019
1 parent aab4922 commit 66cc615
Show file tree
Hide file tree
Showing 34 changed files with 101 additions and 91 deletions.
4 changes: 2 additions & 2 deletions include/gridtools/c_bindings/function_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace gridtools {
template <class T,
typename std::enable_if<std::is_class<typename std::remove_reference<T>::type>::value, int>::type = 0>
gt_handle *convert_to_c(T &&obj) {
return new gt_handle{std::forward<T>(obj)};
return new gt_handle{const_expr::forward<T>(obj)};
}

template <class T>
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace gridtools {
/// Wrap the functor of type `Impl` to another functor that can be invoked with the 'wrapped_t<T>' signature.
template <class T, class Impl>
_impl::wrapped_f<T, typename std::decay<Impl>::type> wrap(Impl &&obj) {
return {std::forward<Impl>(obj)};
return {const_expr::forward<Impl>(obj)};
}

/// Specialization for function pointers.
Expand Down
4 changes: 2 additions & 2 deletions include/gridtools/c_bindings/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace gridtools {
void for_each_param(TypeToStr &&type_to_str, Fun &&fun) {
int count = 0;
for_each_type<Params>(for_each_param_helper_f<TypeToStr, Fun>{
std::forward<TypeToStr>(type_to_str), std::forward<Fun>(fun), count});
const_expr::forward<TypeToStr>(type_to_str), const_expr::forward<Fun>(fun), count});
};

template <class CSignature>
Expand Down Expand Up @@ -439,7 +439,7 @@ namespace gridtools {
get_entities<Traits>().add(name,
std::bind(Traits::template generate_entity<Signature>,
std::placeholders::_1,
std::forward<Params>(params)...));
const_expr::forward<Params>(params)...));
}

template <class CSignature>
Expand Down
7 changes: 4 additions & 3 deletions include/gridtools/common/any_moveable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <utility>

#include "defs.hpp"
#include "generic_metafunctions/utility.hpp"

namespace gridtools {

Expand All @@ -36,7 +37,7 @@ namespace gridtools {
struct impl : iface {
T m_obj;
impl(T const &obj) : m_obj(obj) {}
impl(T &&obj) : m_obj(std::move(obj)) {}
impl(T &&obj) : m_obj(const_expr::move(obj)) {}
std::type_info const &type() const noexcept override { return typeid(T); }
};
std::unique_ptr<iface> m_impl;
Expand All @@ -45,12 +46,12 @@ namespace gridtools {
any_moveable() = default;

template <class Arg, class Decayed = typename std::decay<Arg>::type>
any_moveable(Arg &&arg) : m_impl(new impl<Decayed>(std::forward<Arg>(arg))) {}
any_moveable(Arg &&arg) : m_impl(new impl<Decayed>(const_expr::forward<Arg>(arg))) {}
any_moveable(any_moveable &&) = default;

template <class Arg, class Decayed = typename std::decay<Arg>::type>
any_moveable &operator=(Arg &&obj) {
m_impl.reset(new impl<Decayed>(std::forward<Arg>(obj)));
m_impl.reset(new impl<Decayed>(const_expr::forward<Arg>(obj)));
return *this;
}
any_moveable &operator=(any_moveable &&) = default;
Expand Down
2 changes: 1 addition & 1 deletion include/gridtools/common/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ namespace gridtools {
template <size_t I, typename T, size_t D>
GT_FUNCTION T &&get(array<T, D> &&arr) noexcept {
GT_STATIC_ASSERT(I < D, "index is out of bounds");
return std::move(get<I>(arr));
return const_expr::move(get<I>(arr));
}

/** @} */
Expand Down
3 changes: 2 additions & 1 deletion include/gridtools/common/functional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include <utility>

#include "./generic_metafunctions/utility.hpp"
#include "./host_device.hpp"

#define GT_FILENAME <gridtools/common/functional.hpp>
Expand All @@ -47,7 +48,7 @@ namespace gridtools {
struct ctor {
template <typename... Args>
GT_TARGET GT_FORCE_INLINE T operator()(Args &&... args) const {
return T{std::forward<Args>(args)...};
return T{const_expr::forward<Args>(args)...};
}

#ifndef BOOST_RESULT_OF_USE_DECLTYPE
Expand Down
14 changes: 5 additions & 9 deletions include/gridtools/common/generic_metafunctions/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,28 @@
#include <type_traits>
#include <utility>

#include "../host_device.hpp"

namespace gridtools {
/**
* `std::forward`/`std::move` versions that are guarantied to be constexpr
*/
namespace const_expr {
// cuda < 9.2 doesn't have std::move/std::forward definded as `constexpr`
#if __CUDACC__
// defined(__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ < 9 || __CUDACC_VER_MAJOR__ == 9 &&
// __CUDACC_VER_MINOR__ < 2)
template <class T>
__device__ __host__ typename std::remove_reference<T>::type &&move(T &&obj) noexcept {
GT_HOST_DEVICE typename std::remove_reference<T>::type &&move(T &&obj) noexcept {
return static_cast<typename std::remove_reference<T>::type &&>(obj);
}
template <class T>
__device__ __host__ T &&forward(typename std::remove_reference<T>::type &obj) noexcept {
GT_HOST_DEVICE T &&forward(typename std::remove_reference<T>::type &obj) noexcept {
return static_cast<T &&>(obj);
}
template <class T>
__device__ __host__ T &&forward(typename std::remove_reference<T>::type &&obj) noexcept {
GT_HOST_DEVICE T &&forward(typename std::remove_reference<T>::type &&obj) noexcept {
static_assert(
!std::is_lvalue_reference<T>::value, "Error: obj is instantiated with an lvalue reference type");
return static_cast<T &&>(obj);
}
#else
using std::forward;
using std::move;
#endif
} // namespace const_expr
} // namespace gridtools
4 changes: 2 additions & 2 deletions include/gridtools/common/hypercube_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace gridtools {
size_t InnerD = tuple_size<typename tuple_element<0, Decayed>::type>::value,
typename std::enable_if<OuterD != 0 && InnerD == 2, int>::type = 0>
GT_FUNCTION impl_::hypercube_view<OuterD> make_hypercube_view(Container &&cube) {
auto &&transposed = tuple_util::host_device::transpose(std::forward<Container>(cube));
auto &&transposed = tuple_util::host_device::transpose(const_expr::forward<Container>(cube));
return {tuple_util::host_device::convert_to<array, size_t>(tuple_util::host_device::get<0>(transposed)),
tuple_util::host_device::convert_to<array, size_t>(tuple_util::host_device::get<1>(transposed))};
}
Expand All @@ -107,6 +107,6 @@ namespace gridtools {
typename std::enable_if<D != 0 && std::is_convertible<size_t, typename tuple_element<0, Decayed>::type>::value,
int>::type = 0>
GT_FUNCTION impl_::hypercube_view<D> make_hypercube_view(Container &&sizes) {
return {tuple_util::host_device::convert_to<array, size_t>(std::forward<Container>(sizes))};
return {tuple_util::host_device::convert_to<array, size_t>(const_expr::forward<Container>(sizes))};
}
} // namespace gridtools
19 changes: 11 additions & 8 deletions include/gridtools/common/pair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@ namespace gridtools {
GT_FUNCTION pair(const std::pair<U1, U2> &p) : pair(p.first, p.second) {}

template <class U1, class U2>
GT_FUNCTION pair(std::pair<U1, U2> &&p) : pair(std::move(p.first), std::move(p.second)) {}
GT_FUNCTION pair(std::pair<U1, U2> &&p) : pair(const_expr::move(p.first), const_expr::move(p.second)) {}

template <class U1, class U2>
GT_FUNCTION pair(U1 &&t1_, U2 &&t2_) : first(std::forward<U1>(t1_)), second(std::forward<U2>(t2_)) {}
GT_FUNCTION pair(U1 &&t1_, U2 &&t2_)
: first(const_expr::forward<U1>(t1_)), second(const_expr::forward<U2>(t2_)) {}

template <class U1, class U2, typename std::enable_if<!std::is_same<pair<U1, U2>, pair>::value, int>::type = 0>
GT_FUNCTION pair(const pair<U1, U2> &p) : first(p.first), second(p.second) {}

template <class U1, class U2, typename std::enable_if<!std::is_same<pair<U1, U2>, pair>::value, int>::type = 0>
GT_FUNCTION pair(pair<U1, U2> &&p) : first(std::move(p.first)), second(std::move(p.second)) {}
GT_FUNCTION pair(pair<U1, U2> &&p) : first(const_expr::move(p.first)), second(const_expr::move(p.second)) {}

template <typename U1,
typename U2,
Expand All @@ -60,8 +61,8 @@ namespace gridtools {
typename U2,
typename std::enable_if<!std::is_same<pair<U1, U2>, pair>::value, int>::type = 0>
GT_FUNCTION pair &operator=(pair<U1, U2> &&other) noexcept {
first = std::move(other.first);
second = std::move(other.second);
first = const_expr::move(other.first);
second = const_expr::move(other.second);
return *this;
}

Expand Down Expand Up @@ -141,7 +142,7 @@ namespace gridtools {
}
template <typename T1, typename T2>
static GT_FUNCTION T1 &&move_get(pair<T1, T2> &&p) noexcept {
return std::move(p.first);
return const_expr::move(p.first);
}
};
template <>
Expand All @@ -168,7 +169,8 @@ namespace gridtools {
static GT_FUNCTION auto get(const pair<T1, T2> &p) noexcept GT_AUTO_RETURN(pair_get<I>::const_get(p));

template <size_t I, class T1, class T2>
static GT_FUNCTION auto get(pair<T1, T2> &&p) noexcept GT_AUTO_RETURN(pair_get<I>::move_get(std::move(p)));
static GT_FUNCTION auto get(pair<T1, T2> &&p) noexcept GT_AUTO_RETURN(
pair_get<I>::move_get(const_expr::move(p)));
};
} // namespace pair_impl_

Expand All @@ -179,7 +181,8 @@ namespace gridtools {
GT_FUNCTION auto get(const pair<T1, T2> &p) noexcept GT_AUTO_RETURN(pair_impl_::pair_get<I>::const_get(p));

template <size_t I, class T1, class T2>
GT_FUNCTION auto get(pair<T1, T2> &&p) noexcept GT_AUTO_RETURN(pair_impl_::pair_get<I>::move_get(std::move(p)));
GT_FUNCTION auto get(pair<T1, T2> &&p) noexcept GT_AUTO_RETURN(
pair_impl_::pair_get<I>::move_get(const_expr::move(p)));

template <class T1, class T2>
pair_impl_::getter tuple_getter(pair<T1, T2> const &);
Expand Down
4 changes: 2 additions & 2 deletions include/gridtools/common/permute_to.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace gridtools {
Res<Elems...> operator()(Src &&src) {
using src_t = decay_t<Src>;
return Res<Elems...>{
tuple_util::get<meta::st_position<src_t, Elems>::value>(std::forward<Src>(src))...};
tuple_util::get<meta::st_position<src_t, Elems>::value>(const_expr::forward<Src>(src))...};
}
};
} // namespace impl_
Expand Down Expand Up @@ -62,6 +62,6 @@ namespace gridtools {

template <typename Res, typename Src>
Res permute_to(Src &&src) {
return impl_::permute_to_impl<Res>{}(std::forward<Src>(src));
return impl_::permute_to_impl<Res>{}(const_expr::forward<Src>(src));
}
} // namespace gridtools
17 changes: 9 additions & 8 deletions include/gridtools/common/split_args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "../meta/type_traits.hpp"
#include "../meta/zip.hpp"
#include "defs.hpp"
#include "generic_metafunctions/utility.hpp"

namespace gridtools {
namespace _impl {
Expand All @@ -49,20 +50,20 @@ namespace gridtools {

template <class Args, template <class...> class L, class... Is>
auto get_part_helper(Args &&args, L<Is...> *)
GT_AUTO_RETURN(std::forward_as_tuple(std::get<Is::value>(std::forward<Args>(args))...));
GT_AUTO_RETURN(std::forward_as_tuple(std::get<Is::value>(const_expr::forward<Args>(args))...));

template <template <class...> class Pred, class Args>
auto get_part(Args &&args) GT_AUTO_RETURN(get_part_helper(
std::forward<Args>(args), (GT_META_CALL(make_filtered_indicies, (Pred, Args)) *)(nullptr)));
const_expr::forward<Args>(args), (GT_META_CALL(make_filtered_indicies, (Pred, Args)) *)(nullptr)));

template <template <class...> class Pred, class Args>
auto raw_split_args_tuple(Args &&args)
GT_AUTO_RETURN(std::make_pair(get_part<Pred>(std::forward<Args>(args)),
get_part<meta::not_<Pred>::template apply>(std::forward<Args>(args))));
GT_AUTO_RETURN(std::make_pair(get_part<Pred>(const_expr::forward<Args>(args)),
get_part<meta::not_<Pred>::template apply>(const_expr::forward<Args>(args))));

template <template <class...> class Pred, class Args>
auto split_args_tuple(Args &&args)
GT_AUTO_RETURN(raw_split_args_tuple<apply_to_decayed<Pred>::template apply>(std::forward<Args>(args)));
auto split_args_tuple(Args &&args) GT_AUTO_RETURN(
raw_split_args_tuple<apply_to_decayed<Pred>::template apply>(const_expr::forward<Args>(args)));
} // namespace _split_args
} // namespace _impl

Expand All @@ -78,10 +79,10 @@ namespace gridtools {
*/
template <template <class...> class Pred, class... Args>
auto raw_split_args(Args &&... args)
GT_AUTO_RETURN(raw_split_args_tuple<Pred>(std::forward_as_tuple(std::forward<Args>(args)...)));
GT_AUTO_RETURN(raw_split_args_tuple<Pred>(std::forward_as_tuple(const_expr::forward<Args>(args)...)));

/// A handy variation of raw_split_args that applies predicate on decayed argument types.
template <template <class...> class Pred, class... Args>
auto split_args(Args &&... args)
GT_AUTO_RETURN(split_args_tuple<Pred>(std::forward_as_tuple(std::forward<Args>(args)...)));
GT_AUTO_RETURN(split_args_tuple<Pred>(std::forward_as_tuple(const_expr::forward<Args>(args)...)));
} // namespace gridtools
3 changes: 2 additions & 1 deletion include/gridtools/common/timer/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
#pragma once

#include "../generic_metafunctions/utility.hpp"
#include "../host_device.hpp"
#include <cmath>
#include <sstream>
Expand All @@ -24,7 +25,7 @@ namespace gridtools {
template <typename TimerImpl>
class timer {
protected:
timer(std::string name) : m_name(std::move(name)) {}
timer(std::string name) : m_name(const_expr::move(name)) {}

public:
/**
Expand Down
7 changes: 4 additions & 3 deletions include/gridtools/common/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ namespace gridtools {
conjunction<std::is_assignable<Ts &, Args &&>...>::value,
int> = 0>
GT_FUNCTION void assign(tuple_impl<meta::index_sequence<Is...>, Args...> &&src) noexcept {
void((int[]){(tuple_leaf_getter::get<Is>(*this) = tuple_leaf_getter::get<Is>(std::move(src)), 0)...});
void((int[]){
(tuple_leaf_getter::get<Is>(*this) = tuple_leaf_getter::get<Is>(const_expr::move(src)), 0)...});
}
};
} // namespace impl_
Expand Down Expand Up @@ -189,7 +190,7 @@ namespace gridtools {

template <class Other>
GT_FUNCTION auto operator=(Other &&other)
GT_AUTO_RETURN((m_impl.assign(std::forward<Other>(other).m_impl), *this));
GT_AUTO_RETURN((m_impl.assign(const_expr::forward<Other>(other).m_impl), *this));
};

template <class T>
Expand Down Expand Up @@ -255,7 +256,7 @@ namespace gridtools {

template <class Arg, enable_if_t<std::is_assignable<T &, Arg &&>::value, int> = 0>
GT_FUNCTION tuple &operator=(tuple<Arg> &&src) noexcept {
m_value = std::move(src).m_value;
m_value = const_expr::move(src).m_value;
return *this;
}
};
Expand Down
5 changes: 3 additions & 2 deletions include/gridtools/distributed_boundaries/bound_bc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ namespace gridtools {
* template argument list to the corresponding data members
*/
template <typename ST>
bound_bc(BCApply bca, ST &&stores_list) : m_bcapply(bca), m_stores{std::forward<stores_type>(stores_list)} {}
bound_bc(BCApply bca, ST &&stores_list)
: m_bcapply(bca), m_stores{const_expr::forward<stores_type>(stores_list)} {}

/**
* @brief Function to retrieve the tuple of data stores to pass to the the boundary
Expand Down Expand Up @@ -268,7 +269,7 @@ namespace gridtools {
ro_store_tuple, m_stores, meta::make_index_sequence<std::tuple_size<decltype(m_stores)>::value>{});

return bound_bc<BCApply, decltype(full_list), typename _impl::comm_indices<stores_type>::type>{
m_bcapply, std::move(full_list)};
m_bcapply, const_expr::move(full_list)};
}
};

Expand Down
4 changes: 2 additions & 2 deletions include/gridtools/stencil_composition/arg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace gridtools {

arg_storage_pair() = default;
arg_storage_pair(const DataStoreType &val) : m_value{val} {}
arg_storage_pair(DataStoreType &&val) noexcept : m_value{std::move(val)} {}
arg_storage_pair(DataStoreType &&val) noexcept : m_value{const_expr::move(val)} {}
~arg_storage_pair() = default;

DataStoreType m_value;
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace gridtools {

template <typename Arg>
arg_storage_pair<plh, DataStoreType> operator=(Arg &&arg) const {
return {std::forward<Arg>(arg)};
return {const_expr::forward<Arg>(arg)};
}
};

Expand Down
6 changes: 3 additions & 3 deletions include/gridtools/stencil_composition/computation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace gridtools {

template <class... Args>
void operator()(Args &&... args) const {
m_obj.run(std::forward<Args>(args)...);
m_obj.run(const_expr::forward<Args>(args)...);
}
};

Expand Down Expand Up @@ -78,7 +78,7 @@ namespace gridtools {
struct impl : iface, _impl::computation_detail::impl_arg<impl<Obj>, Args>... {
Obj m_obj;

impl(Obj &&obj) : m_obj{std::move(obj)} {}
impl(Obj &&obj) : m_obj{const_expr::move(obj)} {}

void run(arg_storage_pair_crefs_t const &args) override {
tuple_util::apply(_impl::computation_detail::run_f<Obj>{m_obj}, args);
Expand All @@ -95,7 +95,7 @@ namespace gridtools {
computation() = default;

template <class Obj>
computation(Obj obj) : m_impl(new impl<Obj>{std::move(obj)}) {
computation(Obj obj) : m_impl(new impl<Obj>{const_expr::move(obj)}) {
GT_STATIC_ASSERT((!std::is_same<typename std::decay<Obj>::type, computation>::value),
GT_INTERNAL_ERROR_MSG("computation move ctor got shadowed"));
// TODO(anstaf): Check that Obj satisfies computation concept here.
Expand Down
Loading

0 comments on commit 66cc615

Please sign in to comment.