<commit_before>= Universal resource handling class template for C++ 
This is the unviersal class resource class. All init and cleanup routines can be expressed as 
policies, with a good defaults already provided.

== replacing `unique_ptr`
```cpp
using Res = resource<int>;
Res ptr1{new int{42}};
Res ptr2; // ptr2{nullptr}

// ptr2 = ptr1; // error
ptr2 = std::move(ptr1); // ok

// ptr2 gets deleted at the end of scope
```

=== with an array
```cpp
using Res = resource<int[]>;
Res ptr1{new int[42]};
Res ptr2; // ptr2{nullptr}

// ptr2 = ptr1; // error
ptr2 = std::move(ptr1); // ok

// ptr2 gets delete[]d at the end of scope
```

=== with custom deleter
```cpp
using deleter = cleanup::function_deleter<void(void*), &free>;
using Res = resource<void, deleter::impl>;
Res ptr1{malloc(1024)};
Res ptr2; // ptr2{nullptr}

// ptr2 = ptr1; // error
ptr2 = std::move(ptr1); // ok

// ptr2 gets freed at the end of scope
```

== With your file descriptor RAII class
`unique_ptr` cannot do this - at least not without pointless allocation. 
```cpp
using deleter = cleanup::function_deleter<int(int), &close>;

using Res = resource<
	traits::handle_is_type<int, traits::nullable::yes, int, -1>,
	deleter::impl
>;

Res r1{open("/dev/random", O_RDONLY)};
Res r2; // initialized with -1

assert(*r2 == -1)
// r2 = r1; // error, but the copy policy can be convinced to use dup(2)
r2 = std::move(r1);

// r2 gets close(2)d.
```

= Why? My `unique_ptr` and `lock_guard` are better/good enough?
Most likely you're right. This was is a programming exercise.

= License
If you really want to use this, look [here](LICENSE.md).

<commit_msg>typo fix<commit_after># Universal resource handling class template for C++ 
This is the unviersal class resource class. All init and cleanup routines can be expressed as 
policies, with a good defaults already provided.

## replacing `unique_ptr`
```cpp
using Res = resource<int>;
Res ptr1{new int{42}};
Res ptr2; // ptr2{nullptr}

// ptr2 = ptr1; // error
ptr2 = std::move(ptr1); // ok

// ptr2 gets deleted at the end of scope
```

### with an array
```cpp
using Res = resource<int[]>;
Res ptr1{new int[42]};
Res ptr2; // ptr2{nullptr}

// ptr2 = ptr1; // error
ptr2 = std::move(ptr1); // ok

// ptr2 gets delete[]d at the end of scope
```

### with custom deleter
```cpp
using deleter = cleanup::function_deleter<void(void*), &free>;
using Res = resource<void, deleter::impl>;
Res ptr1{malloc(1024)};
Res ptr2; // ptr2{nullptr}

// ptr2 = ptr1; // error
ptr2 = std::move(ptr1); // ok

// ptr2 gets freed at the end of scope
```

## With your file descriptor RAII class
`unique_ptr` cannot do this - at least not without pointless allocation. 
```cpp
using deleter = cleanup::function_deleter<int(int), &close>;

using Res = resource<
	traits::handle_is_type<int, traits::nullable::yes, int, -1>,
	deleter::impl
>;

Res r1{open("/dev/random", O_RDONLY)};
Res r2; // initialized with -1

assert(*r2 == -1)
// r2 = r1; // error, but the copy policy can be convinced to use dup(2)
r2 = std::move(r1);

// r2 gets close(2)d.
```

# Why? My `unique_ptr` and `lock_guard` are better/good enough?
Most likely you're right. This was is a programming exercise.

# License
If you really want to use this, look [here](LICENSE.md).


{'fraction_non_alphanumeric': 0.15072285450630576, 'fraction_numerical': 0.027683789603199015, 'mean_word_length': 4.049689440993789, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '7497492', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1102, 'n_words': 403}