Skip to content

Commit

Permalink
Minor optimization to avoid warnings ref #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mnesarco committed Nov 15, 2023
1 parent 3759240 commit 7571cde
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions imgui_sugar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

#include <imgui/imgui.h>
#include <imgui.h>

// clang-format off

Expand All @@ -44,10 +44,7 @@ namespace ImGuiSugar
BooleanGuard<AlwaysCallEnd>& operator=(const BooleanGuard<AlwaysCallEnd>&) = delete; // NOLINT
BooleanGuard<AlwaysCallEnd>& operator=(BooleanGuard<AlwaysCallEnd>&&) = delete; // NOLINT

~BooleanGuard() noexcept
{
if (AlwaysCallEnd || m_state) { m_end(); }
}
~BooleanGuard() noexcept;

operator bool() const & noexcept { return m_state; } // (Implicit) NOLINT

Expand All @@ -56,6 +53,15 @@ namespace ImGuiSugar
const ScopeEndCallback m_end;
};

template<>
inline BooleanGuard<true>::~BooleanGuard() noexcept { m_end(); }

template<>
inline BooleanGuard<false>::~BooleanGuard() noexcept
{
if (m_state) { m_end(); }
}

// For special cases, transform void(*)(int) to void(*)()
inline void PopStyleColor() { ImGui::PopStyleColor(1); };
inline void PopStyleVar() { ImGui::PopStyleVar(1); };
Expand Down

0 comments on commit 7571cde

Please sign in to comment.