Skip to content

Instantly share code, notes, and snippets.

@PureAbstract
PureAbstract / pointer_cast_snippet.cpp
Last active December 18, 2015 22:09
dynamic_pointer_cast snippet
for( auto& element : elements )
{
if( auto c = std::dynamic_pointer_cast<C>( element ) )
{
c->BehaveLikeC();
}
if( auto d = std::dynamic_pointer_cast<D>( element ) )
{
DoSomething(d);
@PureAbstract
PureAbstract / gist:6598949
Created September 17, 2013 18:51
parse unsigned UDL
#include <type_traits>
#include <limits>
#include <cstdint>
namespace detail {
template<std::uintmax_t Value>
constexpr std::uintmax_t parse_unsigned_literal()
{
return Value;
@PureAbstract
PureAbstract / Catch_toString.cpp
Created September 17, 2013 21:52
Try and show how toString and StringMaker interact.
// ==================== 1) Overload Catch::toString
struct ts_overload { }; // have an overload of toString
namespace Catch {
std::string toString( const ts_overload& )
{
return "ts:ts_overload";
}
}