Listing 2: The implementation of swap.
void swap(StrongStorage& other)
{
using std::swap;
if(other.cacheInitialized)
{
getOtherCache().template construct_as<value_type>(other.value());
}
try
{
if(cacheInitialized)
{
other.getOtherCache().template
construct_as<value_type>(value());
}
}
catch(...)
{
if(other.cacheInitialized)
{
getOtherCache().template destroy_as<value_type>();
}
throw;
}
if(cacheInitialized)
{
getCache().template destroy_as<value_type>();
}
if(other.cacheInitialized)
{
other.getCache().template destroy_as<value_type>();
}
useCache1=!useCache1;
other.useCache1=!other.useCache1;
swap(cacheInitialized,other.cacheInitialized);
}