<commit_before>// -*- C++ -*- (c) 2013 <NAME>

#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<commit_msg>wibble: Import raii (defer) patch from upstream.<commit_after>// -*- C++ -*- (c) 2013 <NAME>

#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 );
}

template< typename Fn >
struct Defer {
    Defer( Fn fn ) : fn( fn ) { }
    void run() {
        if ( !_deleted ) {
            fn();
            _deleted = true;
        }
    }
    bool deleted() const { return _deleted; }
    ~Defer() { run(); }
  private:
    Fn fn;
    bool _deleted;
};

template< typename Fn >
Defer< Fn > defer( Fn fn ) { return Defer< Fn >( fn ); }

}
}

#endif // WIBBLE_RAII_H

#endif
{'fraction_non_alphanumeric': 0.12552184803785138, 'fraction_numerical': 0.0055663790704146955, 'mean_word_length': 3.2785714285714285, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7209885', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1121, 'n_words': 336}