Ticket #3051: variant.patch

File variant.patch, 5.0 KB (added by Daniel James, 13 years ago)

Patch for both variant and blank, with tests and a little documentation.

  • boost/blank.hpp

     
    1515
    1616#include "boost/blank_fwd.hpp"
    1717
     18#if !defined(BOOST_NO_IOSTREAM)
    1819#include <iosfwd> // for std::basic_ostream forward declare
     20#include "boost/detail/templated_streams.hpp"
     21#endif // BOOST_NO_IOSTREAM
    1922
    20 #include "boost/detail/templated_streams.hpp"
    2123#include "boost/mpl/bool.hpp"
    2224#include "boost/type_traits/is_empty.hpp"
    2325#include "boost/type_traits/is_pod.hpp"
     
    8587
    8688// streaming support
    8789//
     90#if !defined(BOOST_NO_IOSTREAM)
     91
    8892BOOST_TEMPLATED_STREAM_TEMPLATE(E,T)
    8993inline BOOST_TEMPLATED_STREAM(ostream, E,T)& operator<<(
    9094      BOOST_TEMPLATED_STREAM(ostream, E,T)& out
     
    9599    return out;
    96100}
    97101
     102#endif // BOOST_NO_IOSTREAM
     103
    98104} // namespace boost
    99105
    100106#endif // BOOST_BLANK_HPP
  • boost/variant/variant.hpp

     
    1515
    1616#include <cstddef> // for std::size_t
    1717#include <new> // for placement new
     18
     19#if !defined(BOOST_NO_TYPEID)
    1820#include <typeinfo> // for typeid, std::type_info
     21#endif // BOOST_NO_TYPEID
    1922
    2023#include "boost/variant/detail/config.hpp"
    2124#include "boost/mpl/aux_/config/eti.hpp"
     
    691694//
    692695// Generic static visitor that performs a typeid on the value it visits.
    693696//
     697
     698#if !defined(BOOST_NO_TYPEID)
     699
    694700class reflect
    695701    : public static_visitor<const std::type_info&>
    696702{
     
    704710
    705711};
    706712
     713#endif // BOOST_NO_TYPEID
     714
    707715///////////////////////////////////////////////////////////////////////////////
    708716// (detail) class comparer
    709717//
     
    16271635        return false;
    16281636    }
    16291637
     1638#if !defined(BOOST_NO_TYPEID)
    16301639    const std::type_info& type() const
    16311640    {
    16321641        detail::variant::reflect visitor;
    16331642        return this->apply_visitor(visitor);
    16341643    }
     1644#endif
    16351645
    16361646public: // prevent comparison with foreign types
    16371647
     
    18231833} // namespace boost
    18241834
    18251835// implementation additions
     1836
     1837#if !defined(BOOST_NO_IOSTREAM)
    18261838#include "boost/variant/detail/variant_io.hpp"
     1839#endif // BOOST_NO_IOSTREAM
    18271840
    18281841#endif // BOOST_VARIANT_VARIANT_HPP
  • libs/variant/test/jobs.h

     
    232232
    233233
    234234
     235// This is not used and breaks when BOOST_NO_TYPEID is defined
     236//struct held_type_name : boost::static_visitor<std::string>
     237//{
     238//   
     239//   template<typename T>
     240//   std::string operator()(const T& ) const
     241//   {
     242//      ost_ << '[' << typeid(T).name() << ']';
     243//      return result();
     244//   }
     245//
     246//   std::string result() const
     247//   {
     248//      return ost_.str();
     249//   }
     250//
     251//   mutable std::ostringstream ost_;
     252//
     253//}; //held_type_name
    235254
    236 struct held_type_name : boost::static_visitor<std::string>
    237 {
    238    
    239    template<typename T>
    240    std::string operator()(const T& ) const
    241    {
    242       ost_ << '[' << typeid(T).name() << ']';
    243       return result();
    244    }
    245255
    246    std::string result() const
    247    {
    248       return ost_.str();
    249    }
    250256
    251    mutable std::ostringstream ost_;
    252 
    253 }; //held_type_name
    254 
    255 
    256 
    257 
    258257template<typename T>
    259258struct spec
    260259{
     
    267266   const VariantType& cvar = var;
    268267
    269268   BOOST_CHECK(boost::apply_visitor(total_sizeof(), cvar) == sizeof(S));
     269#if !defined(BOOST_NO_TYPEID)
    270270   BOOST_CHECK(cvar.type() == typeid(S));
     271#endif
    271272
    272273   //
    273274   // Check get<>()
     
    316317{
    317318   const VariantType& cvar = var;
    318319
     320#if !defined(BOOST_NO_TYPEID)
    319321   BOOST_CHECK(cvar.type() != typeid(S));
     322#endif
    320323
    321324   //
    322325   // Check get<>()
  • libs/variant/test/test3.cpp

     
    122122   std::ostringstream e1_str;
    123123   e1_str << e1;
    124124
     125#if !defined(BOOST_NO_TYPEID)
    125126   BOOST_CHECK(e1.type() == typeid(Add));
     127#endif
    126128   BOOST_CHECK(e1_str.str() == "(13+((40+2)-(10+4)))");
    127129
    128130   //Evaluate expression
  • libs/variant/doc/reference/variant.xml

     
    364364          </returns>
    365365
    366366          <throws>Will not throw.</throws>
     367         
     368          <notes>
     369            <simpara>Not available when <code>BOOST_NO_TYPEID</code> is
     370              defined.</simpara>
     371          </notes>
    367372        </method>
    368373
    369374      </method-group>
     
    536541        <simpara>Calls <code>out &lt;&lt; x</code>, where <code>x</code> is
    537542          the content of <code>rhs</code>.</simpara>
    538543      </effects>
     544     
     545      <notes>
     546        <simpara>Not available when <code>BOOST_NO_IOSTREAM</code> is
     547          defined.</simpara>
     548      </notes>
     549
    539550    </function>
    540551   
    541552    <class name="make_variant_over">