Skip to content

Commit

Permalink
Change to ConstStringRef
Browse files Browse the repository at this point in the history
Made it use std::visit() instead of std::holds_alternative()
  • Loading branch information
Vaughn Cato committed Aug 10, 2023
1 parent 6a6b861 commit d3887e4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions include/ftxui/util/ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ class ConstStringRef {

const std::string_view getStringView() const
{
if ( std::holds_alternative<std::string_view>(variant_) )
return std::get<std::string_view>(variant_);
else if ( std::holds_alternative<std::string *>(variant_) )
return *std::get<std::string *>(variant_);
else if ( std::holds_alternative<std::string>(variant_) )
return std::get<std::string>(variant_);
struct Fn {
std::string_view operator()(std::string_view x) const { return x; }
std::string_view operator()(std::string &x) const { return x; }
std::string_view operator()(std::string *x) const { return *x; }
};

return std::visit(Fn(), variant_);
}
};

Expand Down

0 comments on commit d3887e4

Please sign in to comment.