// boost::compressed_pair test program // (C) Copyright John Maddock 2000. Permission to copy, use, modify, sell and // distribute this software is granted provided this copyright notice appears // in all copies. This software is provided "as is" without express or implied // warranty, and with no claim as to its suitability for any purpose. // standalone test program for #include #include #include #include #include "type_traits_test.hpp" using namespace boost; struct empty_POD_UDT{}; struct empty_UDT { ~empty_UDT(){}; }; namespace boost { #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION template <> struct is_empty { static const bool value = true; }; template <> struct is_empty { static const bool value = true; }; template <> struct is_POD { static const bool value = true; }; #else template <> struct is_empty { enum{ value = true }; }; template <> struct is_empty { enum{ value = true }; }; template <> struct is_POD { enum{ value = true }; }; #endif } int main() { compressed_pair cp1(1, 1.3); assert(cp1.first() == 1); assert(cp1.second() == 1.3); compressed_pair cp1b(2, 2.3); assert(cp1b.first() == 2); assert(cp1b.second() == 2.3); swap(cp1, cp1b); assert(cp1b.first() == 1); assert(cp1b.second() == 1.3); assert(cp1.first() == 2); assert(cp1.second() == 2.3); #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION compressed_pair cp2(2); assert(cp2.second() == 2); #endif compressed_pair cp3(1); assert(cp3.first() ==1); compressed_pair cp4; compressed_pair cp5; #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION int i = 0; compressed_pair cp6(i,i); assert(cp6.first() == i); assert(cp6.second() == i); assert(&cp6.first() == &i); assert(&cp6.second() == &i); compressed_pair cp7; cp7.first(); double* pd = cp7.second(); #endif value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) value_test(true, (sizeof(compressed_pair) < sizeof(std::pair))) value_test(true, (sizeof(compressed_pair >) < sizeof(std::pair >))) std::cout << std::endl << test_count << " tests completed (" << failures << " failures)... press any key to exit"; std::cin.get(); return failures; } // // instanciate some compressed pairs: #ifdef __MWERKS__ template class compressed_pair; template class compressed_pair; template class compressed_pair; template class compressed_pair; template class compressed_pair; template class compressed_pair; #else template class boost::compressed_pair; template class boost::compressed_pair; template class boost::compressed_pair; template class boost::compressed_pair; template class boost::compressed_pair; template class boost::compressed_pair; #endif #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION // // now some for which only a few specific members can be instantiated, // first references: template double& compressed_pair::first(); template int& compressed_pair::second(); template compressed_pair::compressed_pair(int&); template compressed_pair::compressed_pair(call_traits::param_type,int&); // // and then arrays: #ifndef __MWERKS__ #ifndef __BORLANDC__ template call_traits::reference compressed_pair::second(); #endif template call_traits::reference compressed_pair::first(); template compressed_pair::compressed_pair(const double&); template compressed_pair::compressed_pair(); #endif // __MWERKS__ #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION