Home Blog/Rants Downloads C++ Papers GitHub LinkedIn
Michael-Maniscalco.com
Code snippets and thoughts on the C++ programming language
Some crazy C++ shiznit
January 11, 2017
If you wanted to encapsulate a reference to a C++ const character array and provide the ability to access that value without it decaying to a char const * you would write something like the following. How's this for crazy-assed C++ syntax?!
template <std::size_t N>
class const_char_array_wrapper
{
public:
   
    const_char_array_wrapper
    (
        char const (&value)[N]
    ):
        value_(value)
    {
    }

    char const
    (
        & get_value() const
    )[N]
    {
        return value_;
    }

    // or, for implicit conversions

    (
        & operator char const () const
    )[N]
    {
        return value_;
    }

private:

  char const (&value_)[N];
};