Boost logo

Boost :

From: Peter Simons (simons_at_[hidden])
Date: 2002-08-02 09:49:34


Just curious: Shouldn't the property of a variable being unset or being
set (and having a value in the latter case) be usable more generally?
In a project of mine, I used the following template to achieve this:

    template <typename varT>
    class resetable_variable
        {
      public:
        typedef varT value_type;

        resetable_variable()
                : is_set(false)
            {
            }
        resetable_variable(const value_type& val)
                : value(val), is_set(true)
            {
            }
        resetable_variable<value_type>& operator= (const value_type& rhs)
            {
            value = rhs;
            is_set = true;
            return *this;
            }
        const value_type& data() const throw()
            {
            return value;
            }
        operator const value_type&() const throw()
            {
            return value;
            }
        bool empty() const throw()
            {
            return !is_set;
            }

      private:
        value_type value;
        bool is_set;
        };

This was used when parsing configuration files in order to know which
values had been set in the file and which had not.

    -peter


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk