www.digitalmars.com         C & C++   DMDScript  

c++.stlsoft - Run-time Union List

reply "christopher diggins" <cdiggins videotron.ca> writes:
I would like to submit the code for a run-time union list to StlSoft, if 
there is any interest in it. This type behaves like a union, as it can hold 
one value of an arbitrary list of types. It does not have the property of 
memory sharing however. It does however have a very small code-base unlike 
the similar boost::variant. I want to release the code as public domain, 
would that make it incompatible with the STLSoft licensing requirements?

Here is how the code is used:

#include "..\utils\union_list.hpp"

#include <string>
#include <iostream>

using namespace std;

typedef ul<int, ul<char, ul<bool, ul<double, ul<string, ul_end> > > > > 
test_type;

void output(test_type x) {
  switch(x.DataIndex()) {
    case 0 : cout << "int : " << x.get<0>() << endl; break;
    case 1 : cout << "char : " << x.get<1>() << endl; break;
    case 2 : cout << "bool : " << x.get<2>() << endl; break;
    case 3 : cout << "float : " << x.get<3>() << endl; break;
    case 4 : cout << "string : " << x.get<4>() << endl; break;
  }
}

int main() {
  output('a');
  output(3.141);
  output(42);
  output(string("Hello world"));
  output(true);
  getchar();
  return 0;
}

Is this something that is desirable?

-- 
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com 
Jan 03 2005
parent reply "christopher diggins" <cdiggins videotron.ca> writes:
I posted the entire union list code at 
http://www.codeproject.com/useritems/union_list.asp .
Any interest in having it in STLSoft?

(still preparing the next release of the YARD parser)

-- 
Christopher Diggins
http://www.cdiggins.com
http://www.heron-language.com 
Jan 04 2005
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
Sorry, Chris

Madly snowed under at the mo. Will have to get back to you next week.

Cheers

Matthew

"christopher diggins" <cdiggins videotron.ca> wrote in message 
news:cren41$2kk9$1 digitaldaemon.com...
I posted the entire union list code at 
http://www.codeproject.com/useritems/union_list.asp .
 Any interest in having it in STLSoft?

 (still preparing the next release of the YARD parser)

 -- 
 Christopher Diggins
 http://www.cdiggins.com
 http://www.heron-language.com
 
Jan 04 2005