Boost logo

Boost :

From: Paul A Bristow (pbristow_at_[hidden])
Date: 2006-07-10 09:23:39


There is some overlap in function between this and the floating-point
NaN(s).

A way of representing 'missing values' is a very common requirement for
numerical data in the sciences from physics to sociology.

The potential value of this has been discussed, especially noting the need
for way of inputting and outputing for serialization, for one important
example, and I have made a proposal (of sorts) in

http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n2022.pdf

Input and output of NaN and infinity.

Without this, NaN (and infinity) is much less useful than it could be.

Although the fallible concept obviously can work, I see a key disadvantage
for big arrays of data is the need for an extra byte to hold the valid bit.
And after packing and/or loss of alignment, it could be a LOT worse -
perhaps doubling the storage required.

Paul

---
Paul A Bristow
Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB
+44 1539561830 & SMS, Mobile +44 7714 330204 & SMS
pbristow_at_[hidden]
  
|  -----Original Message-----
|  From: boost-bounces_at_[hidden] 
|  [mailto:boost-bounces_at_[hidden]] On Behalf Of Gennaro Prota
|  Sent: 10 July 2006 13:34
|  To: boost_at_[hidden]
|  Subject: [boost] Interest in Barton-Nackman's fallible<T>?
|  
|  Hi guys,
|  
|  I don't know how and how much boost:optional<> overlaps with this
|  (last time I checked it was different, but I know there's a proposal
|  in which the template has been changed), anyway: is there 
|  interest for
|  a Barton-Nackman's fallible<T> template? Basically the idea is
|  (warning: not compiled):
|  
|  #include <assert.h>
|  
|  template<typename T>
|  class fallible
|  {
|  public :
|               fallible();
|      explicit fallible(const T & value);
|  
|  
|      bool is_valid() const;
|  
|      const T& value() const;
|      operator T() const;
|  
|      const T& else_default_to(const T& default_value) const;
|  
|      void invalidate();
|      void validate(const T& value); // alternative to operator=
|  
|  private :
|  
|      T    m_value;
|      bool m_valid;
|  
|  };
|  
|  template<typename T>
|  fallible<T>::fallible()
|   : m_valid(false)
|  {
|  }
|  
|  
|  template<typename T>
|  fallible<T>::fallible( const T& v )
|   : m_value(v), m_valid(true)
|  {
|  }
|  
|  template<typename T>
|  bool
|  fallible<T>::is_valid() const
|  {
|      return m_valid;
|  }
|  
|  template<typename T>
|  const T&
|  fallible<T>::value() const
|  {
|      assert(m_valid);  // <---
|      return m_value;
|  }
|  
|  template<typename T>
|  fallible<T>::operator T() const
|  {
|      return value();
|  }
|  
|  template<typename T>
|  const T&
|  fallible<T>::else_default_to(const T& default_value) const
|  {
|      return is_valid()
|          ?   static_cast<const T&>(value())
|          :   static_cast<const T&>(default_value);
|  }
|  
|  template<typename T>
|  void
|  fallible<T>::invalidate()
|  {
|      m_valid = false;
|  }
|  
|  template <typename T>
|  void
|  fallible<T>::validate(const T& value)
|  {
|      m_value = value;
|      m_valid = true;
|  }
|  
|  
|  --
|  [ Gennaro Prota, C++ developer for hire ]
|  [    resume:  available on request      ]
|  
|  _______________________________________________
|  Unsubscribe & other changes: 
|  http://lists.boost.org/mailman/listinfo.cgi/boost
|  

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