Skip to content

Commit

Permalink
Use shimmed std::as_const instead of qAsConst
Browse files Browse the repository at this point in the history
  • Loading branch information
PhysSong committed Apr 4, 2020
1 parent 8d908c6 commit 1746300
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 21 additions & 1 deletion include/stdshims.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#define STDSHIMS_H

#include <memory>
#include <type_traits>
#include <utility>

#if (__cplusplus >= 201402L || _MSC_VER)
#ifndef _MSC_VER
#warning "This file should now be removed! The functions it provides are part of the C++14 standard."
#warning "This part of this file should now be removed! The functions it provides are part of the C++14 standard."
#endif
using std::make_unique;

Expand All @@ -30,5 +31,24 @@ std::unique_ptr<T, Deleter> make_unique(Args&&... args)
}
#endif

#if (__cplusplus >= 201703L || _MSC_VER >= 1914)
#ifndef _MSC_VER
#warning "This part of this file should now be removed! The functions it provides are part of the C++17 standard."
#endif
using std::as_const;

#else

/// Shim for http://en.cppreference.com/w/cpp/utility/as_const
template <typename T>
constexpr typename std::add_const<T>::type& as_const(T& t) noexcept
{
return t;
}

template <typename T>
void as_const(const T&&) = delete;
#endif

#endif // include guard

4 changes: 3 additions & 1 deletion src/gui/widgets/ControlLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@

#include "ControlLayout.h"

#include "stdshims.h"

#include <QWidget>
#include <QLayoutItem>
#include <QLineEdit>
Expand Down Expand Up @@ -208,7 +210,7 @@ QSize ControlLayout::minimumSize() const
// get maximum height and width for all children.
// as Qt will later call heightForWidth, only the width here really matters
QSize size;
for (const QLayoutItem *item : qAsConst(m_itemMap))
for (const QLayoutItem *item : as_const(m_itemMap))
{
size = size.expandedTo(item->minimumSize());
}
Expand Down

0 comments on commit 1746300

Please sign in to comment.