Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

noexcept specifier

27 views
Skip to first unread message

Mark

unread,
Mar 28, 2019, 7:28:16 AM3/28/19
to
I'm trying to make sense of the noexcept specifier so given the following

// noexceptOperator.cpp

#include <iostream>
#include <array>
#include <vector>

class NoexceptCopy{
public:
std::array<int, 5> arr{1, 2, 3, 4, 5}; // (2)
};

class NonNoexceptCopy{
public:
std::vector<int> v{1, 2, 3, 4 , 5}; // (3)
};

template <typename T>
T copy(T const& src) noexcept(noexcept(T(src))) { // (1)
std::cout << " called " << std::endl;
return src;
}

int main(){

NoexceptCopy noexceptCopy;
NonNoexceptCopy nonNoexceptCopy;

std::cout << std::boolalpha << std::endl;

std::cout << "noexcept(copy(noexceptCopy)): " << // (4)
noexcept(copy(noexceptCopy)) << std::endl;

std::cout << "noexcept(copy(nonNoexceptCopy)): " << // (5)
noexcept(copy(nonNoexceptCopy)) << std::endl;

std::cout << std::endl;

}

Need a reading on where the call to copy fits in given copy (noexceptCopy) or copy (nonNoexceptCopy ) never gets invoked ('called is not outputted) and 'noexcept(T(src))' appears to boil down to

noexcept ( NoexceptCopy )
noexcept ( NonNoexceptCopy )

thanks in advance

Öö Tiib

unread,
Mar 28, 2019, 8:20:12 AM3/28/19
to
That should say

noexcept(copy(noexceptCopy)): true
noexcept(copy(nonNoexceptCopy)): false

Is there some reason of doubt about it?
Can you elaborate for example what is unclear in online reference like:
https://en.cppreference.com/w/cpp/language/noexcept

> Need a reading on where the call to copy fits in given copy (noexceptCopy) or copy (nonNoexceptCopy ) never gets invoked ('called is not outputted) and 'noexcept(T(src))' appears to boil down to
>
> noexcept ( NoexceptCopy )
> noexcept ( NonNoexceptCopy )
>
> thanks in advance

It does not matter since expressions given as arguments of operators like sizeof
or noexcept do not get "invoked", just the types of those are evaluated compile
time.

Mark

unread,
Mar 28, 2019, 8:38:16 AM3/28/19
to
On Thursday, March 28, 2019 at 8:20:12 AM UTC-4, Öö Tiib wrote:
>
> It does not matter since expressions given as arguments of operators like sizeof
> or noexcept do not get "invoked", just the types of those are evaluated compile
> time.

Ah! I'm following now. I might have missed the 'operator' context in noexcept
0 new messages