From d1d30416993f605004e31fc615cb02368c357161 Mon Sep 17 00:00:00 2001 From: Joshie Date: Wed, 4 Sep 2024 17:07:03 +0000 Subject: [PATCH] Support for std::string_view in proxy_base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows code like the following to work: ```cpp std::string_view pretty_name = my_table["pretty_name"]; ``` Otherwise it fails with: ``` error: conversion from ‘sol::table_proxy >&, std::tuple >’ to non-scalar type ‘std::string_view’ {aka ‘std::basic_string_view’} requested 2131 | std::string_view psvPrettyName = tTable["pretty_name"]; | ``` --- include/sol/proxy_base.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/sol/proxy_base.hpp b/include/sol/proxy_base.hpp index c473554a..3934182b 100644 --- a/include/sol/proxy_base.hpp +++ b/include/sol/proxy_base.hpp @@ -49,6 +49,11 @@ namespace sol { return super.template get(); } + operator std::string_view() const { + const Super& super = *static_cast(static_cast(this)); + return super.template get(); + } + template >, is_proxy_primitive>> = meta::enabler> operator T() const { const Super& super = *static_cast(static_cast(this));