From f15f8dd5a73a8017d6bcbda6b2b60b00ddb1c48f Mon Sep 17 00:00:00 2001 From: ThePhD Date: Sun, 24 Apr 2016 17:31:32 -0400 Subject: [PATCH] const-correctness since nobody is going to let me be fuckin' lazy .-. --- sol/variadic_args.hpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/sol/variadic_args.hpp b/sol/variadic_args.hpp index 9666ceb7..802795e3 100644 --- a/sol/variadic_args.hpp +++ b/sol/variadic_args.hpp @@ -28,7 +28,8 @@ #include namespace sol { - struct va_iterator : std::iterator { + template + struct va_iterator : std::iterator, std::ptrdiff_t, std::conditional_t, std::conditional_t> { lua_State* L; int index; int stacktop; @@ -37,12 +38,11 @@ namespace sol { va_iterator() : L(nullptr), index(std::numeric_limits::max()), stacktop(std::numeric_limits::max()) {} va_iterator(lua_State* L, int index, int stacktop) : L(L), index(index), stacktop(stacktop), sp(L, index) {} - stack_proxy operator*() { - sp = stack_proxy(L, index); - return sp; + reference operator*() { + return stack_proxy(L, index); } - stack_proxy* operator->() { + pointer operator->() { sp = stack_proxy(L, index); return &sp; } @@ -89,7 +89,7 @@ namespace sol { return r; } - stack_proxy operator[](difference_type idx) { + reference operator[](difference_type idx) { return stack_proxy(L, index + static_cast(idx)); } @@ -123,8 +123,9 @@ namespace sol { return index >= r.index; } }; - - inline va_iterator operator+(typename va_iterator::difference_type n, const va_iterator& r) { + + template + inline va_iterator operator+(typename va_iterator::difference_type n, const va_iterator& r) { return r + n; } @@ -140,8 +141,8 @@ public: typedef stack_proxy* pointer; typedef std::ptrdiff_t difference_type; typedef std::size_t size_type; - typedef va_iterator iterator; - typedef const va_iterator const_iterator; + typedef va_iterator iterator; + typedef va_iterator const_iterator; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; @@ -170,10 +171,10 @@ public: return *this; } - iterator begin() { return va_iterator(L, index, stacktop + 1); } - iterator end() { return va_iterator(L, stacktop + 1, stacktop + 1); } - const_iterator begin() const { return va_iterator(L, index, stacktop + 1); } - const_iterator end() const { return va_iterator(L, stacktop + 1, stacktop + 1); } + iterator begin() { return iterator(L, index, stacktop + 1); } + iterator end() { return iterator(L, stacktop + 1, stacktop + 1); } + const_iterator begin() const { return const_iterator(L, index, stacktop + 1); } + const_iterator end() const { return const_iterator(L, stacktop + 1, stacktop + 1); } const_iterator cbegin() const { return begin(); } const_iterator cend() const { return end(); }