Type safe variadic cout implementation I use console a lot, so I thought this may help me. It's supposed to be simple, safe, and fast. Any ideas?

http://ideone.com/INXub0

#include &lt;iostream&gt;
using namespace std;

class Console
{
public:
    template&lt;typename ...Args&gt;
    static bool WriteLine(const std::string&amp; format, Args&amp;&amp;... args)
    {
        bool success = write(format.c_str(), std::forward&lt;Args&gt;(args)...);
        std::cout &lt;&lt; std::endl;
        return success;
    }

    template &lt;typename ...Args&gt;
    static bool Write(const std::string&amp; format, Args&amp;&amp;... args)
    {
        return write(format.c_str(), std::forward&lt;Args&gt;(args)...);
    }

    template&lt;typename T&gt;
    static void WriteLine(T&amp;&amp; value)
    {
        std::cout &lt;&lt; std::forward&lt;T&gt;(value) &lt;&lt; std::endl;
    }

    template&lt;typename T&gt;
    static void Write(T&amp;&amp; value)
    {
        std::cout &lt;&lt; std::forward&lt;T&gt;(value);
    }

private:
    template&lt;typename ...Args&gt;
    static bool write(const char * format, Args&amp;&amp;... args)
    {
        while (*format)
        {
            if (*format == '{')
            {
                bool found_closing_brace = false;
                short value_position = -1;

                while (*(++format))
                {
                    if (*format == '}')
                    {
                        if (value_position == -1)
                            return false;  // {} is not allowed.

                        write_value(value_position, 0, std::forward&lt;Args&gt;(args)...);
                        found_closing_brace = true;
                        break;
                    }
                    else
                    {
                        if (value_position &gt;= 10)
                            return false; //Only range {0 ~ 99} is allowed. 

                        if (value_position == -1)
                            value_position = *format - '0';
                        else
                            value_position = (value_position * 10) + (*format - '0');
                    }
                }

                if (!found_closing_brace)
                    return false; 

                // Continue back to the main loop. This is required.
                // We need to process the next character, because it could be a '\0' or a '{'
                format++;
                continue;
            }

            std::cout &lt;&lt; *format;
            format++;
        }

        return true;
    }

    template&lt;typename T, typename ...Args&gt;
    static void write_value(int x, int i, T&amp;&amp; value, Args&amp;&amp;... values)
    {
        if (i == x)
            std::cout &lt;&lt; std::forward&lt;T&gt;(value);
        else
            write_value(x, ++i, std::forward&lt;Args&gt;(values)...);
    }

    static void write_value(int x, int i) { }   
};

int main()
{
    Console::WriteLine("Big {11} Bang {0} Theory {6} [{11}, {12}]",

        "Zero", "One", "Two", "Three", "Four", "Five",
        "Six", "Seven", 8, "Nine", "Teen", 11, 12.5f);

    // your code goes here
    return 0;
}
You must allow the escape character for { and } otherwise this doesn't works.

Console::WriteLine("int {0}(){ return 0; }", function_name);


Apart from that I would add an override to specify the output stream.

std::ofstream logger("log.err");
Console::WriteLine(logger, "String");


It must be a class? Probably it's only a style issue, but I don't like class with only static methods. I prefer namespace and a console_details namespace for private functions.