Why ais there true, and b- false? Or, in other words, why Tis foo1there int const, but is the return type foo2equal int?
a
true
b
false
T
foo1
int const
foo2
int
template<typename T> constexpr bool foo1(T &) { return std::is_const<T>::value; } template<typename T> T foo2(T &); int main() { int const x = 0; constexpr bool a = foo1(x); constexpr bool b = std::is_const<decltype(foo2(x))>::value; }
const-qualifiers are ignored if the return type of the function is non-classical and not an array. If you use some class instead of plain int, it will produce 1 1:
struct Bar{}; int main() { Bar const x{}; constexpr bool a = foo1(x); constexpr bool b = std::is_const<decltype(foo2(x))>::value; }
online compiler
, const int foo2<const int>(const int&);, const int, foo2(x) const int. , const ( volatile) prvalues non-array, non-class ( int). " " , int, decltype.
const int foo2<const int>(const int&);
const int
foo2(x)
const
volatile
decltype
Source: https://habr.com/ru/post/1691845/More articles:How to remove border selection on after clicking - htmlIf a CancellationToken is a structure and passed in a value, how is it updated? - parameter-passingНевозможно связать параметр 'log', чтобы ввести TraceWriter - c#How to use Feature2D (e.g. SimpleBlobDetector)? (Python + OpenCV) - pythonIs it possible to smooth an array with a length of 700,000 records without exceeding the call stack? - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1691846/viewgroup-inside-collapsingtoolbarlayout-show-extra-bottom-padding-when-set-fitssystemwindows-to-be-true&usg=ALkJrhgZP6ymvD0BLkCAvvcVwWfI6UyacQAdd button to graphic canvas - androidHuffman coding in MATLAB - dictionary / tree transfer - matlabSymfony. После представления формы не содержится ни одного элемента в ArrayCollection для его полей из CollectionType - symfonyFill in the entry matrix from arrays of column / row indexes - pythonAll Articles