<commit_before>// reverse_view.hpp: wrapper function to reverse a container iteration for range based loops
//
// Copyright (C) 2017-2019 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

#include <iterator>
#include <type_traits>
#include <utility>

namespace sw {
namespace unum {

#if NO_XVALUE_CONTAINER_REQUIRED
	// Reverse container view
	template<typename Container>
	class ReverseContainerView {
	public:
		explicit ReverseContainerView(Container& c)
			: m_container{ c }
		{}
		auto begin() {
			return std::rbegin(m_container);
		}
		auto end() {
			return std::rend(m_container);
		}
	private:
		Container& m_container;
	};

	template<typename Container>
	auto reverse(Container& c) {
		return ReverseContainerView<Container>(c);
	}

	template<typename Container>
	auto reverse(const Container& cc) {
		return ReverseContainerView<const Container>(cc);
	}

#else
	// for cases where the container is an xvalue, we need to copy the contents
	// if we want to apply a reverse view on it
	template<typename Ty, bool CopyValue = !std::is_lvalue_reference_v<Ty> >
	struct ContainerContainer;

	// lvalue ContainerContainer: contains a reference to the container
	template<typename Ty>
	struct ContainerContainer<Ty, false> {
		Ty& c;
		explicit ContainerContainer(Ty& c)
			: c{ c }
		{}
	};

	// rvalue ContainerContainer: contains a reference to the container
	template<typename Ty>
	struct ContainerContainer<Ty, true> {
		
		const Ty c;
		explicit ContainerContainer(Ty& c)
			: c{ std::move(c) }// move will construct a new copy of the container
		{}
	};

	template<typename Container>
	class ReverseContainerView : ContainerContainer<Container> {
		using Base = ContainerContainer<Container>;
	public:
		explicit ReverseContainerView(Container&& c)
			: Base{ std::forward<Container>(c) }
		{}

		auto begin() {
			return std::rbegin(Base::c);
		}
		auto end() {
			return std::rend(Base::c);
		}
	};

	template<typename Container>
	auto reverse(Container&& c) {
		return ReverseContainerView<Container>(std::forward<Container>(c));
	}

#endif // NO_XVALUE_CONTAINER_REQUIRED

} // unum
} // sw<commit_msg>is_lvalue_reference_v<Ty> is equivalent to is_lvalue_reference<Ty>::value to appease g++<commit_after>// reverse_view.hpp: wrapper function to reverse a container iteration for range based loops
//
// Copyright (C) 2017-2019 Stillwater Supercomputing, Inc.
//
// This file is part of the universal numbers project, which is released under an MIT Open Source license.

#include <iterator>
#include <type_traits>
#include <utility>

namespace sw {
namespace unum {

#if NO_XVALUE_CONTAINER_REQUIRED
	// Reverse container view
	template<typename Container>
	class ReverseContainerView {
	public:
		explicit ReverseContainerView(Container& c)
			: m_container{ c }
		{}
		auto begin() {
			return std::rbegin(m_container);
		}
		auto end() {
			return std::rend(m_container);
		}
	private:
		Container& m_container;
	};

	template<typename Container>
	auto reverse(Container& c) {
		return ReverseContainerView<Container>(c);
	}

	template<typename Container>
	auto reverse(const Container& cc) {
		return ReverseContainerView<const Container>(cc);
	}

#else
	// for cases where the container is an xvalue, we need to copy the contents
	// if we want to apply a reverse view on it
	template<typename Ty, bool CopyValue = !std::is_lvalue_reference<Ty>::value >
	struct ContainerContainer;

	// lvalue ContainerContainer: contains a reference to the container
	template<typename Ty>
	struct ContainerContainer<Ty, false> {
		Ty& c;
		explicit ContainerContainer(Ty& c)
			: c{ c }
		{}
	};

	// rvalue ContainerContainer: contains a reference to the container
	template<typename Ty>
	struct ContainerContainer<Ty, true> {
		
		const Ty c;
		explicit ContainerContainer(Ty& c)
			: c{ std::move(c) }// move will construct a new copy of the container
		{}
	};

	template<typename Container>
	class ReverseContainerView : ContainerContainer<Container> {
		using Base = ContainerContainer<Container>;
	public:
		explicit ReverseContainerView(Container&& c)
			: Base{ std::forward<Container>(c) }
		{}

		auto begin() {
			return std::rbegin(Base::c);
		}
		auto end() {
			return std::rend(Base::c);
		}
	};

	template<typename Container>
	auto reverse(Container&& c) {
		return ReverseContainerView<Container>(std::forward<Container>(c));
	}

#endif // NO_XVALUE_CONTAINER_REQUIRED

} // unum
} // sw
{'fraction_non_alphanumeric': 0.10701598579040852, 'fraction_numerical': 0.003552397868561279, 'mean_word_length': 4.4939024390243905, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, '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': '357926', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1353, 'n_words': 414}