Skip to content

Commit

Permalink
alter. to avoid constructor taking range itself
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Grützmacher <thomas.gruetzmacher@kit.edu>
  • Loading branch information
yhmtsai and Thomas Grützmacher committed Jul 21, 2021
1 parent d6e76b1 commit 317ddd7
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions accessor/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

namespace gko {
namespace acc {
namespace {


/**
* the default check_if_valid gives true.
*
* @tparam Ref the reference type
* @tparam Args the input type
*/
template <typename Ref, typename... Args>
struct check_if_valid : public std::true_type {};

/**
* check_if_valid gives false if the decay type of input is the same type as
* Ref.
*
* @tparam Ref the reference type
*/
template <typename Ref>
struct check_if_valid<Ref, Ref> : public std::false_type {};


} // namespace


template <typename Accessor>
Expand All @@ -66,14 +89,16 @@ class range {
* Creates a new range.
*
* @tparam AccessorParam types of parameters forwarded to the accessor
* constructor
* constructor. It does not allow range itself.
*
* @param params parameters forwarded to Accessor constructor.
*/
template <typename... AccessorParams,
std::enable_if_t<(sizeof...(AccessorParams) > 1), bool> = true>
GKO_ACC_ATTRIBUTES constexpr explicit range(AccessorParams &&... params)
: accessor_{std::forward<AccessorParams>(params)...}
std::enable_if_t<
check_if_valid<range, std::decay_t<AccessorParams>...>::value,
int> = 0>
GKO_ACC_ATTRIBUTES constexpr explicit range(AccessorParams &&... args)
: accessor_{std::forward<AccessorParams>(args)...}
{}

/**
Expand Down

0 comments on commit 317ddd7

Please sign in to comment.