/usr/include/wibble/raii.h is in libwibble-dev 1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | // -*- C++ -*- (c) 2013 Vladimír Štill
#if __cplusplus >= 201103L
#include <utility>
#include <type_traits>
#ifndef WIBBLE_RAII_H
#define WIBBLE_RAII_H
namespace wibble {
namespace raii {
template< typename Instance,
typename Delete = void(*)( typename std::remove_reference< Instance >::type & ) >
struct AutoDelete {
Instance value;
Delete deleter;
AutoDelete( Instance &&instance, Delete deleter ) :
AutoDelete( true, std::forward< Instance >( instance ), deleter )
{ }
AutoDelete( bool runDeleter, Instance &&instance, Delete deleter ) :
value( std::forward< Instance >( instance ) ),
deleter( deleter ), runDeleter( runDeleter )
{ }
~AutoDelete() {
if ( runDeleter )
deleter( value );
}
private:
bool runDeleter;
};
template< typename Creator, typename Delete >
auto autoDeleter( Creator creator, Delete deleter )
-> AutoDelete< typename std::result_of< Creator() >::type, Delete >
{
using Instance = typename std::result_of< Creator() >::type;
return AutoDelete< Instance, Delete >( true, creator(), deleter );
}
template< typename Instance, typename Delete >
auto refDeleteIf( bool cond, Instance &ref, Delete deleter )
-> AutoDelete< Instance &, Delete >
{
return AutoDelete< Instance &, Delete >( cond, ref, deleter );
}
template< typename Instance, typename Delete >
auto refDeleter( Instance &ref, Delete deleter )
-> AutoDelete< Instance &, Delete >
{
return refDeleteIf( true, ref, deleter );
}
}
}
#endif // WIBBLE_RAII_H
#endif
|