From cd82fccde7855a6bdc2a4873f1057167a2419c75 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Tue, 18 Jan 2022 22:48:58 +0400 Subject: [PATCH] Add missing const. (#297) Co-authored-by: ArthurSonzogni --- include/ftxui/screen/screen.hpp | 4 ++-- include/ftxui/util/ref.hpp | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/ftxui/screen/screen.hpp b/include/ftxui/screen/screen.hpp index 5120472..9e609b6 100644 --- a/include/ftxui/screen/screen.hpp +++ b/include/ftxui/screen/screen.hpp @@ -62,8 +62,8 @@ class Screen { void Print(); // Get screen dimensions. - int dimx() { return dimx_; } - int dimy() { return dimy_; } + int dimx() const { return dimx_; } + int dimy() const { return dimy_; } // Move the terminal cursor n-lines up with n = dimy(). std::string ResetPosition(bool clear = false); diff --git a/include/ftxui/util/ref.hpp b/include/ftxui/util/ref.hpp index 2eb7eb5..ff1133a 100644 --- a/include/ftxui/util/ref.hpp +++ b/include/ftxui/util/ref.hpp @@ -13,9 +13,9 @@ class ConstRef { ConstRef() {} ConstRef(T t) : owned_(t) {} ConstRef(const T* t) : address_(t) {} - const T& operator*() { return address_ ? *address_ : owned_; } - const T& operator()() { return address_ ? *address_ : owned_; } - const T* operator->() { return address_ ? address_ : &owned_; } + const T& operator*() const { return address_ ? *address_ : owned_; } + const T& operator()() const { return address_ ? *address_ : owned_; } + const T* operator->() const { return address_ ? address_ : &owned_; } private: T owned_; @@ -82,8 +82,10 @@ class ConstStringRef { ConstStringRef(const wchar_t* ref) : ConstStringRef(std::wstring(ref)) {} ConstStringRef(const char* ref) : ConstStringRef(to_wstring(std::string(ref))) {} - const std::string& operator*() { return address_ ? *address_ : owned_; } - const std::string* operator->() { return address_ ? address_ : &owned_; } + const std::string& operator*() const { return address_ ? *address_ : owned_; } + const std::string* operator->() const { + return address_ ? address_ : &owned_; + } private: const std::string owned_;