POV-Ray : Newsgroups : povray.programming : cleaning source code from warnings troubles : Re: cleaning source code from warnings troubles Server Time
28 Jul 2024 14:30:26 EDT (-0400)
  Re: cleaning source code from warnings troubles  
From: Warp
Date: 4 Oct 2002 15:34:57
Message: <3d9ded61@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.