[ create a new paste ] login | about

Link: http://codepad.org/zDJNcqUx    [ raw code | output | fork ]

C++, pasted on Dec 21:
#include <iostream>
#include <string>

bool stdstring_supports_cow()
{
   std::string s1 = "0123456789";
   std::string s2 = s1;
   std::string s3 = s2;

   bool result1 = s1.c_str() == s2.c_str();
   bool result2 = s1.c_str() == s3.c_str();

   s2[0] = 'X';

   bool result3 = s1.c_str() != s2.c_str();
   bool result4 = s1.c_str() == s3.c_str();

   s3[0] = 'X';

   bool result5 = s1.c_str() != s3.c_str();

   return result1 && result2 &&
          result3 && result4 &&
          result5;
}


int main()
{
   if (stdstring_supports_cow())
      std::cout << "std::string is COW." << std::endl;
   else
      std::cout << "std::string is NOT COW." << std::endl;
 
   return 0;
}


Output:
1
std::string is COW.


Create a new paste based on this one


Comments: