Transparency.h#

Fully qualified name: carb/container/Transparency.h

File members: carb/container/Transparency.h

// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.

#pragma once

#include "../Hash.h"

#include "../cpp/StringView.h"

#include <type_traits>

namespace carb::container
{
namespace detail
{
template <typename T, typename = void>
struct IsTransparent : std::false_type
{
};

template <typename T>
struct IsTransparent<T, std::void_t<typename T::is_transparent>> : std::true_type
{
};
} // namespace detail

struct TransparentStringHasher : public std::equal_to<void>
{
    using is_transparent = void;

    size_t operator()(cpp::string_view sv) const
    {
        return carb::hashBuffer(sv.data(), sv.length());
    }
    size_t operator()(const char* p) const
    {
        if (!p)
            p = "";
        return carb::hashString(p);
    }

    using std::equal_to<void>::operator();
};
static_assert(detail::IsTransparent<TransparentStringHasher>::value);
static_assert(detail::IsTransparent<std::equal_to<void>>::value); // check assumptions

using TransparentStringLessCompare = std::less<void>; // the default C++14 std::less<void> supports transparency
static_assert(detail::IsTransparent<std::less<void>>::value); // check assumptions

} // namespace carb::container