Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prevent unused variable warnings when using single row vectors and matrices #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ namespace linalg
// NOTE: vec<T,1> does NOT have a constructor from pointer, this can conflict with initializing its single element from zero
template<class U>
constexpr explicit vec(const vec<U,1> & v) : vec(static_cast<T>(v.x)) {}
constexpr const T & operator[] (int i) const { return x; }
LINALG_CONSTEXPR14 T & operator[] (int i) { return x; }
constexpr const T & operator[] (int i) const { (void)i; return x; }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing i would have the same effect I think:

constexpr const T & operator[] (int) const { return x; }

see https://godbolt.org/z/6E5r88sdx

LINALG_CONSTEXPR14 T & operator[] (int i) { (void)i; return x; }

template<class U, class=detail::conv_t<vec,U>> constexpr vec(const U & u) : vec(converter<vec,U>{}(u)) {}
template<class U, class=detail::conv_t<U,vec>> constexpr operator U () const { return converter<U,vec>{}(*this); }
Expand Down Expand Up @@ -293,8 +293,8 @@ namespace linalg
template<class U>
constexpr explicit mat(const mat<U,M,1> & m) : mat(V(m.x)) {}
constexpr vec<T,1> row(int i) const { return {x[i]}; }
constexpr const V & operator[] (int j) const { return x; }
LINALG_CONSTEXPR14 V & operator[] (int j) { return x; }
constexpr const V & operator[] (int j) const { (void)j; return x; }
LINALG_CONSTEXPR14 V & operator[] (int j) { (void)j; return x; }

template<class U, class=detail::conv_t<mat,U>> constexpr mat(const U & u) : mat(converter<mat,U>{}(u)) {}
template<class U, class=detail::conv_t<U,mat>> constexpr operator U () const { return converter<U,mat>{}(*this); }
Expand Down