<commit_before>/**************************************************************************\
 * simple wrapper for optional values or references                       *
 *                                               ___                      *
 *    /\/\   __ _  __ _ _ __  _   _ _ __ ___     /___\_ __  _   _ ___     *
 *   /    \ / _` |/ _` | '_ \| | | | '_ ` _ \   //  // '_ \| | | / __|    *
 *  / /\/\ \ (_| | (_| | | | | |_| | | | | | | / \_//| |_) | |_| \__ \    *
 *  \/    \/\__,_|\__, |_| |_|\__,_|_| |_| |_| \___/ | .__/ \__,_|___/    *
 *                |___/                              |_|                  *
 *                                                                        *
 * Copyright (c) 2014 <NAME>                                       *
 *                                                                        *
 *  This file is part of MagnumOpus and distributed under the MIT License *
 *  See LICENSE file for details.                                         *
\**************************************************************************/

#pragma once

#include <stdexcept>
#include <functional>
#include <memory>
#include "log.hpp"

namespace mo {
namespace util {

	template<typename T>
	class maybe {
		public:
			/*implicit*/ maybe(T&& data)noexcept : _valid(true), _data(std::move(data)) {}
			/*implicit*/ maybe(const T& data)noexcept : _valid(true), _data(data) {}
			maybe(const maybe& o)noexcept : _valid(o._valid), _data(o._data) {}
			maybe(maybe&& o)noexcept : _valid(o._valid), _data(std::move(o._data)) {
				o._valid = false;
			}
			~maybe()noexcept {
				if(is_some())
					_data.~T();
			}

			operator maybe<const T>()const noexcept {
				return is_some() ? maybe<const T>(_data) : maybe<const T>::nothing();
			}

			maybe& operator=(const maybe& o)noexcept {
				_valid = o._valid;
				_data = o._data;
				return *this;
			}
			maybe& operator=(maybe&& o)noexcept {
				_valid = o._valid;
				if(o._valid) {
					if(_valid)
						_data = o._data;
					else
						_data.T(_data);
				}

				o._valid = false;
				o._data.~T();
				return *this;
			}

			static maybe nothing() noexcept {
				return maybe();
			}


			bool is_some()const noexcept {
				return _valid;
			}
			bool is_nothing()const noexcept {
				return !is_some();
			}

			T& get_or_throw() {
				INVARIANT(is_some(), "Called getOrThrow on nothing.");

				return _data;
			}
			const T& get_or_throw()const {
				INVARIANT(is_some(), "Called getOrThrow on nothing.");

				return _data;
			}
			T& get_or_other(T& other)const noexcept {
				return is_some() ? _data : other;<commit_msg>possible fix for mingw compiler-error<commit_after>/**************************************************************************\
 * simple wrapper for optional values or references                       *
 *                                               ___                      *
 *    /\/\   __ _  __ _ _ __  _   _ _ __ ___     /___\_ __  _   _ ___     *
 *   /    \ / _` |/ _` | '_ \| | | | '_ ` _ \   //  // '_ \| | | / __|    *
 *  / /\/\ \ (_| | (_| | | | | |_| | | | | | | / \_//| |_) | |_| \__ \    *
 *  \/    \/\__,_|\__, |_| |_|\__,_|_| |_| |_| \___/ | .__/ \__,_|___/    *
 *                |___/                              |_|                  *
 *                                                                        *
 * Copyright (c) 2014 <NAME>                                       *
 *                                                                        *
 *  This file is part of MagnumOpus and distributed under the MIT License *
 *  See LICENSE file for details.                                         *
\**************************************************************************/

#pragma once

#include <stdexcept>
#include <functional>
#include <memory>
#include "log.hpp"

namespace mo {
namespace util {

	template<typename T>
	class maybe {
		public:
			/*implicit*/ maybe(T&& data)noexcept : _valid(true), _data(std::move(data)) {}
			/*implicit*/ maybe(const T& data)noexcept : _valid(true), _data(data) {}
			maybe(const maybe& o)noexcept : _valid(o._valid), _data(o._data) {}
			maybe(maybe&& o)noexcept : _valid(o._valid), _data(std::move(o._data)) {
				o._valid = false;
			}
			~maybe()noexcept {
				if(is_some())
					_data.~T();
			}

			operator maybe<const T>()const noexcept {
				return is_some() ? maybe<const T>(_data) : maybe<const T>::nothing();
			}

			maybe& operator=(const maybe& o)noexcept {
				_valid = o._valid;
				_data = o._data;
				return *this;
			}
			maybe& operator=(maybe&& o)noexcept {
				_valid = o._valid;
				if(o._valid) {
					if(_valid)
						_data = o._data;
					else
						_data.T(_data);
				}

				o._valid = false;
				o._data.~T();
				return *this;
			}

			static maybe nothing() noexcept {
				return maybe();
			}


			bool is_some()const noexcept {
				return _valid;
			}
			bool is_nothing()const noexcept {
				return !is_some();
			}

			T& get_or_throw() {
				INVARIANT(is_some(), "Called getOrThrow on nothing.");

				return _data;
			}
			const T& get_or_throw()const {
				INVARIANT(is_some(), "Called getOrThrow on nothing.");

				return _data;
			}
			T& get_ref_or_other(T& other)noexcept {
				return is_some() ? _data : other;
			}
			const T& get_ref_or_other(const T& other)const noexcept {
				return is_some() ? _data : other;
			}
			T get_or_other(T other)const noexcept {
				return is_some() ? _data : other;
{'fraction_non_alphanumeric': 0.19584406031629276, 'fraction_numerical': 0.001471129091577786, 'mean_word_length': 1.6779911373707532, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4193842', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1663, 'n_words': 324}