|
|
Christopher James Huff <chr### [at] maccom> wrote:
> template<typename T>
> inline T select(bool cond, T ifTrue, T ifFalse)
[snip]
> Would it work?
You need to make some different version of the template function in
order to to take into account all the possibilities.
This works in all cases I tested:
#include <iostream>
template<typename T>
inline const T* Select(bool cond, const T* ifTrue, const T* ifFalse)
{
if(cond) return ifTrue;
else return ifFalse;
}
template<typename T>
inline T& Select(bool cond, T& ifTrue, T& ifFalse)
{
if(cond) return ifTrue;
else return ifFalse;
}
template<typename T>
inline const T& Select(bool cond, const T& ifTrue, const T& ifFalse)
{
if(cond) return ifTrue;
else return ifFalse;
}
int main()
{
bool flag = true;
char test[2][4] = { {'o', 'n', 0}, {'o', 'f', 'f', 0} };
Select(flag, test[0], test[1])[0] = 'O';
std::cout << "The flag is " << Select(flag, test[0], test[1]) << std::endl;
std::cout << "The flag is " << Select(flag, "on", "off") << std::endl;
std::cout << "The flag is " << Select(flag, 1, 0) << std::endl;
int i = 0, j = 0;
Select(flag, i, j) = 1;
std::cout << "i=" << i << ", j=" << j << std::endl;
return 0;
}
--
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}// - Warp -
Post a reply to this message
|
|