2021-10-30 04:25:12 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
#pragma once
|
|
|
|
|
2023-11-11 05:10:07 +08:00
|
|
|
#include "Luau/DenseHash.h"
|
2021-10-30 04:25:12 +08:00
|
|
|
#include <ostream>
|
2021-11-05 23:47:21 +08:00
|
|
|
#include <optional>
|
|
|
|
|
2021-11-20 00:10:07 +08:00
|
|
|
namespace std
|
|
|
|
{
|
2021-10-30 04:25:12 +08:00
|
|
|
|
|
|
|
inline std::ostream& operator<<(std::ostream& lhs, const std::nullopt_t&)
|
|
|
|
{
|
|
|
|
return lhs << "none";
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2021-11-05 23:47:21 +08:00
|
|
|
auto operator<<(std::ostream& lhs, const std::optional<T>& t) -> decltype(lhs << *t) // SFINAE to only instantiate << for supported types
|
2021-10-30 04:25:12 +08:00
|
|
|
{
|
|
|
|
if (t)
|
|
|
|
return lhs << *t;
|
|
|
|
else
|
|
|
|
return lhs << "none";
|
|
|
|
}
|
2021-11-05 23:47:21 +08:00
|
|
|
|
2023-11-11 05:10:07 +08:00
|
|
|
template<typename T>
|
|
|
|
auto operator<<(std::ostream& lhs, const std::vector<T>& t) -> decltype(lhs << t[0])
|
|
|
|
{
|
|
|
|
lhs << "{ ";
|
|
|
|
bool first = true;
|
|
|
|
for (const T& element : t)
|
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
first = false;
|
|
|
|
else
|
|
|
|
lhs << ", ";
|
|
|
|
|
|
|
|
lhs << element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lhs << " }";
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename K, typename H, typename E>
|
|
|
|
auto operator<<(std::ostream& lhs, const Luau::DenseHashSet<K, H, E>& set) -> decltype(lhs << *set.begin())
|
|
|
|
{
|
|
|
|
lhs << "{ ";
|
|
|
|
bool first = true;
|
|
|
|
for (const K& element : set)
|
|
|
|
{
|
|
|
|
if (first)
|
|
|
|
first = false;
|
|
|
|
else
|
|
|
|
lhs << ", ";
|
|
|
|
|
|
|
|
lhs << element;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lhs << " }";
|
|
|
|
}
|
|
|
|
|
2021-11-05 23:47:21 +08:00
|
|
|
} // namespace std
|