The Artima Developer Community
Sponsored Link

Weblogs Forum
Yet Another C++ Variant Type

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Yet Another C++ Variant Type (View in Weblogs)
Posted: Jan 4, 2005 11:25 AM
Reply to this message Reply
I have written a new variant / union style type for C++ and posted it to

I have been on a C++ coding bender during the Holidays. While putting together a couple of demo programs for the YARD parser I found I desparately wanted a library which allowed using C++ programs within programs like unix filters, where their standard-in and standard-out can be redirected. While developing this unix-filter library it lead me to desire a variant style type, but I don't like boost::any or boost::variant ( too many dependencies ), so I rolled my own.

So all of this to say, I just posted my latest creation, a union-list type, at

Here is a demonstration of how the type is used:

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

  #include <iostream>

  using namespace std;

  typedef ul<int, ul<char const*, ul_end> > IntOrString_T;

  int main() {
    IntOrString_T i(42);
    IntOrString_T s("hello");
    cout << i.TypeIndex() << endl; // outputs 0
    cout << s.TypeIndex() << endl; // outputs 1
    cout << i.Get<0>() << endl; // outputs 42
    cout << s.Get<1>() << endl; // outputs hello
    return 0;

Topic: No More YACC and LEX Previous Topic   Next Topic Topic: Web Services vs Jini

Sponsored Links


Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use