/**************************************************************************** ** Copyright (c) 2021, Fougue Ltd. ** All rights reserved. ** See license at https://github.com/fougue/mayo/blob/master/LICENSE.txt ****************************************************************************/ #pragma once #include #include #include namespace Mayo { template using Span = gsl::span; // Returns the index of 'item' contained in 'span' template constexpr int Span_itemIndex(Span span, typename Span::const_reference item) { assert(!span.empty()); auto index = &item - &span.front(); assert(index >= 0); assert(index <= INT_MAX); assert(&span[static_cast::size_type>(index)] == &item); return static_cast(index); } template constexpr int Span_itemIndex(const Container& cont, typename Container::const_reference item) { return Span_itemIndex(Span(cont), item); } } // namespace Mayo