/* try.cpp - for trying out some language features.... * scons will create the binary bin/try * */ // 8/07 - how to control NOBUG?? // execute with NOBUG_LOG='ttt:TRACE' bin/try // 1/08 - working out a static initialisation problem for Visitor (Tag creation) // 1/08 - check 64bit longs // 4/08 - comparison operators on shared_ptr // 4/08 - conversions on the value_type used for boost::any // 5/08 - how to guard a downcasting access, so it is compiled in only if the involved types are convertible // 7/08 - combining partial specialisation and subclasses // 10/8 - abusing the STL containers to hold noncopyable values //#include #include "proc/nobugcfg.hpp" #include #include #include #include #include #include "lib/scopedholder.hpp" using std::string; using std::cout; using std::vector; using boost::format; namespace { boost::format fmt ("<%2i>"); long checksum = 0; } namespace funny { class Mrpf : boost::noncopyable { long secret_; typedef Mrpf _ThisType; public: Mrpf() : secret_(0) { cout << "Mrpf() this=" << this <<"\n"; } ~Mrpf() { checksum -= secret_; cout << "~Mrpf() this=" << this <<" skeret="<"< > class Allocator_TransferNoncopyable { typedef Allocator_TransferNoncopyable _ThisType; PAR par_; public: typedef typename PAR::size_type size_type; typedef typename PAR::difference_type difference_type; typedef typename PAR::pointer pointer; typedef typename PAR::const_pointer const_pointer; typedef typename PAR::reference reference; typedef typename PAR::const_reference const_reference; typedef typename PAR::value_type value_type; template struct rebind { typedef Allocator_TransferNoncopyable<_Tp1, PAR> other; }; Allocator_TransferNoncopyable() { } Allocator_TransferNoncopyable(const _ThisType& __a) : par_(__a.par_) { } Allocator_TransferNoncopyable(const PAR& __a) : par_(__a) { } template Allocator_TransferNoncopyable(const std::allocator&) { } ~Allocator_TransferNoncopyable() { } size_type max_size() const { return par_.max_size(); } pointer address(reference r) const { return par_.address(r); } const_pointer address(const_reference cr) const { return par_.address(cr); } pointer allocate(size_type n, const void *p=0){ return par_.allocate(n,p); } void deallocate(pointer p, size_type n) { return par_.deallocate(p,n); } void destroy(pointer p) { return par_.destroy(p); } void construct (pointer p, const TY& ref) { cout << "Allo::construct( p="<(ref), *p); } }; template inline bool operator== (Allocator_TransferNoncopyable<_T1> const&, Allocator_TransferNoncopyable<_T2> const&) { return true; } template inline bool operator!= (Allocator_TransferNoncopyable<_T1> const&, Allocator_TransferNoncopyable<_T2> const&) { return false; } typedef Allocator_TransferNoncopyable Allo; int main (int argc, char* argv[]) { NOBUG_INIT; vector mrmpf; mrmpf.reserve(2); mrmpf.push_back(funny::Mrpf()); mrmpf[0].setup(33); cout << ".....resize:\n"; mrmpf.resize(5); cout << "Summmmmmmmmmmmmmmmmmmm="<