ladybird/AK/TemporaryChange.h
Timothy Flynn 3961a4f16a AK: Fully qualify use of move in TemporaryChange
For some reason, after some seemingly unrelated upcoming changes, the
unqualified `move`s in this header result in an ADL failure:

AK/TemporaryChange.h:22:39: error: call to function 'move' that is
neither visible in the template definition nor found by argument-
dependent lookup
   22 |     ~TemporaryChange() { m_variable = move(m_old_value); }
      |                                       ^

Libraries/LibDNS/Resolver.h:491:29: note: in instantiation of member
function 'AK::TemporaryChange<bool>::~TemporaryChange' requested here
  491 |             TemporaryChange change(m_attempting_restart, true);
2025-03-22 17:27:45 +01:00

38 lines
611 B
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Platform.h>
#include <AK/StdLibExtras.h>
namespace AK {
template<typename T>
class TemporaryChange {
public:
TemporaryChange(T& variable, T value)
: m_variable(variable)
, m_old_value(AK::move(variable))
{
m_variable = AK::move(value);
}
~TemporaryChange()
{
m_variable = AK::move(m_old_value);
}
private:
T& m_variable;
T m_old_value;
};
}
#if USING_AK_GLOBALLY
using AK::TemporaryChange;
#endif