/*
 * Copyright 2015 - 2025 gary@drinkingtea.net
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

#pragma once

#if __has_include(<string>)
#include <string>
#include <string_view>
#endif

namespace ox {

// Maybe StringView. If T is a string type, MaybeType::type/MaybeView_t is a
// StringView. This avoids creating unnecessary Strings when taking a
// StringView or C string as a function argument.
template<typename T>
struct MaybeView {
	using type = T;
};

template<typename T>
using MaybeView_t = typename MaybeView<T>::type;

#if __has_include(<string>)
template<typename CharT, typename Traits, typename Allocator>
struct MaybeView<std::basic_string<CharT, Traits, Allocator>> {
	using type = std::basic_string_view<CharT, Traits>;
};
#endif

}
