Skip to content

Commit

Permalink
Merge explicit gko::dim operator bool
Browse files Browse the repository at this point in the history
This PR makes the conversion operator from gko::dim to bool explicit, which causes it to be only used
in contexts that expect booleans (logic operators, conditional statements, ...) or by explicit conversion.

Related PR: #650
  • Loading branch information
upsj authored Oct 17, 2020
2 parents 9dc9bc1 + d5388dd commit ed4f8a2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/ginkgo/core/base/dim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ struct dim {
* different than zero.
*
* @return true if and only if all dimensions evaluate to true
*
* @note This operator is explicit to avoid implicit dim-to-int casts.
* It will still be used in contextual conversions (if, &&, ||, !)
*/
constexpr GKO_ATTRIBUTES operator bool() const
explicit constexpr GKO_ATTRIBUTES operator bool() const
{
return static_cast<bool>(first_) && static_cast<bool>(rest_);
}
Expand Down Expand Up @@ -183,7 +186,7 @@ struct dim<1u, DimensionType> {
return GKO_ASSERT(dimension == 0), first_;
}

constexpr GKO_ATTRIBUTES operator bool() const
explicit constexpr GKO_ATTRIBUTES operator bool() const
{
return static_cast<bool>(first_);
}
Expand Down

0 comments on commit ed4f8a2

Please sign in to comment.