Skip to content

Commit ad5e4ec

Browse files
committed
fix constexpr ig
1 parent 642057b commit ad5e4ec

File tree

3 files changed

+150
-1
lines changed

3 files changed

+150
-1
lines changed

glm/detail/type_vec2.inl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,60 @@ namespace glm
106106
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i)
107107
{
108108
GLM_ASSERT_LENGTH(i, this->length());
109+
110+
# if GLM_LANG & GLM_LANG_CXX14_FLAG || GLM_LANG & GLM_LANG_CXX17_FLAG
111+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
112+
if (std::is_constant_evaluated())
113+
{
114+
# endif
115+
switch (i)
116+
{
117+
default:
118+
case 0:
119+
return x;
120+
case 1:
121+
return y;
122+
}
123+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
124+
}
125+
else
126+
{
127+
return (&x)[i];
128+
}
129+
# endif
130+
# else
109131
return (&x)[i];
132+
# endif
110133
}
111134

112135
template<typename T, qualifier Q>
113136
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<2, T, Q>::operator[](typename vec<2, T, Q>::length_type i) const
114137
{
115138
GLM_ASSERT_LENGTH(i, this->length());
139+
140+
# if GLM_LANG & GLM_LANG_CXX14_FLAG || GLM_LANG & GLM_LANG_CXX17_FLAG
141+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
142+
if (std::is_constant_evaluated())
143+
{
144+
# endif
145+
switch (i)
146+
{
147+
default:
148+
case 0:
149+
return x;
150+
case 1:
151+
return y;
152+
}
153+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
154+
}
155+
else
156+
{
157+
return (&x)[i];
158+
}
159+
# endif
160+
# else
116161
return (&x)[i];
162+
# endif
117163
}
118164

119165
// -- Unary arithmetic operators --

glm/detail/type_vec3.inl

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,63 @@ namespace glm
171171
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T & vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i)
172172
{
173173
GLM_ASSERT_LENGTH(i, this->length());
174+
# if GLM_LANG & GLM_LANG_CXX14_FLAG || GLM_LANG & GLM_LANG_CXX17_FLAG
175+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
176+
if (std::is_constant_evaluated())
177+
{
178+
# endif
179+
switch (i)
180+
{
181+
default:
182+
case 0:
183+
return x;
184+
case 1:
185+
return y;
186+
case 2:
187+
return z;
188+
}
189+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
190+
}
191+
else
192+
{
193+
return (&x)[i];
194+
}
195+
# endif
196+
# else
174197
return (&x)[i];
198+
# endif
175199
}
176200

177201
template<typename T, qualifier Q>
178202
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<3, T, Q>::operator[](typename vec<3, T, Q>::length_type i) const
179203
{
180204
GLM_ASSERT_LENGTH(i, this->length());
205+
206+
# if GLM_LANG & GLM_LANG_CXX14_FLAG || GLM_LANG & GLM_LANG_CXX17_FLAG
207+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
208+
if (std::is_constant_evaluated())
209+
{
210+
# endif
211+
switch (i)
212+
{
213+
default:
214+
case 0:
215+
return x;
216+
case 1:
217+
return y;
218+
case 2:
219+
return z;
220+
}
221+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
222+
}
223+
else
224+
{
225+
return (&x)[i];
226+
}
227+
# endif
228+
# else
181229
return (&x)[i];
230+
# endif
182231
}
183232

184233
// -- Unary arithmetic operators --

glm/detail/type_vec4.inl

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,68 @@ namespace detail
362362
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i)
363363
{
364364
GLM_ASSERT_LENGTH(i, this->length());
365-
return (&x)[i];
365+
366+
# if GLM_LANG & GLM_LANG_CXX14_FLAG || GLM_LANG & GLM_LANG_CXX17_FLAG
367+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
368+
if (std::is_constant_evaluated())
369+
{
370+
# endif
371+
switch (i)
372+
{
373+
default:
374+
case 0:
375+
return x;
376+
case 1:
377+
return y;
378+
case 2:
379+
return z;
380+
case 3:
381+
return w;
382+
}
383+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
384+
}
385+
else
386+
{
387+
return (&x)[i];
388+
}
389+
# endif
390+
# else
391+
return (&x)[i];
392+
# endif
366393
}
367394

368395
template<typename T, qualifier Q>
369396
GLM_FUNC_QUALIFIER GLM_CONSTEXPR T const& vec<4, T, Q>::operator[](typename vec<4, T, Q>::length_type i) const
370397
{
371398
GLM_ASSERT_LENGTH(i, this->length());
399+
400+
# if GLM_LANG & GLM_LANG_CXX14_FLAG || GLM_LANG & GLM_LANG_CXX17_FLAG
401+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
402+
if (std::is_constant_evaluated())
403+
{
404+
# endif
405+
switch (i)
406+
{
407+
default:
408+
case 0:
409+
return x;
410+
case 1:
411+
return y;
412+
case 2:
413+
return z;
414+
case 3:
415+
return w;
416+
}
417+
# if GLM_LANG & GLM_LANG_CXX20_FLAG
418+
}
419+
else
420+
{
421+
return (&x)[i];
422+
}
423+
# endif
424+
# else
372425
return (&x)[i];
426+
# endif
373427
}
374428

375429
// -- Unary arithmetic operators --

0 commit comments

Comments
 (0)