Boost logo

Boost :

From: Tom Brinkman (reportbase_at_[hidden])
Date: 2008-03-18 23:47:56

As you know, you can't pass a string as a template parameter.
Nevertheless, I have found
that I often need to do just that.

This small utility allows you to pass a string as a parameter. I call
it "static_string".

This could possibly given to one of the google students as an easy
project. Otherwise,
here an example of what I do to solve this problem.

typedef static_string<'H','E','L','P'> help_t;
std::string help = help_t();
BOOST_CHECK(help == "help");

template <typename T>
void foo()
       std::string str = T();
       BOOST_CHECK(str == "help");


template <char a=' ',
        char b=' ',
        char c=' ',
        char d=' ',
        char e=' ',
        char f=' ',
        char g=' ',
        char h=' '>
        char i=' '>
        char j=' '>
        char k=' '>
        char l=' '>
struct static_string
        operator std::string()
                char ch[7];
                std::string str = ch;
                return str;

Boost list run by bdawes at, gregod at, cpdaniel at, john at