Sponsored Link •
|
Summary
I have written a new variant / union style type for C++ and posted it to CodeProject.com.
Advertisement
|
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 CodeProject.com.
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; }
Have an opinion? Be the first to post a comment about this weblog entry.
If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.
Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com. |
Sponsored Links
|