Why isn't argument deduction allowed in function return type?

why isn't my brain working pdf
why isn't my brain working supplements
why isn't my brain working audiobook
why isn't my brain working reddit
why isn't my brain working book
netflix error code
is netflix down or is it just me
netflix app not working

The most obvious answer could be - because the standard says so. That's fine, but I'm wrapping my head around it to understand the reasons behind this choice.

Consider the following example:

template<typename T>
struct S { S(T) {} };

S f() { return 0; }

int main() {
    auto s = f();
    (void)s;
}

It fails to compile with errors like:

error: use of class template 'S' requires template arguments; argument deduction not allowed in function return type

Quite easy to fix, it isn't a problem, something like this works just fine:

auto f() { return S{0}; }

However, I'd like to understand what were the drawbacks of allowing class template arguments deduction also in function return types. At a first glance, it looks just like a silly limitation, but I'm pretty sure I'm missing something important here.

Stefan Al: Why isn't the Netherlands underwater?, Why isn't the Netherlands underwater? Share this idea. Facebook. LinkedIn. Twitter. Created Duration: 4:56 Posted: Mar 24, 2020 Why? Although new episodes will return next week, today’s is a rerun because of changes set in place due to the coronavirus outbreak. ‘General Hospital’ Is Airing Flashback Fridays Because

Why isn't argument deduction allowed in function return type?

Because the standard says so.

You could ask the question: why is there a difference between these lines of code:

S s = 0;            // OK
S s() { return 0; } // error - even though this is also copy-initializing an "S" from 0

You could come up with a handwavy explanation of why the first one should be okay and why the second one should not be - but fundamentally class template argument deduction was proposed to only address the first case and not the second. The first one is okay because the standard says so, and the second one is an error because the standard says so.

There is an extension proposed (P1021, under "Return type deduction for functions") that would address the second case. Whether or not you think this is a good idea... ¯\_(ツ)_/¯

Why isn't the Netherlands underwater?, In January 1953, a tidal surge shook the North Sea. The titanic waves flooded the Dutch coastline Duration: 5:24 Posted: Jan 15, 2020 Why Isn’t There a Diet That Works for Everyone? Credit Illustration by Ori Toor. “It’s also why there have been so many conflicting studies in nutrition,” Mayer-Davis says. “The

Just my hand-wavy two cents that summarize my understanding:

In

S f() { return 0; }

the S is no type that could be deduced, its just a template. You could write

template<typename T>
S<T> f() { return 0;}

but now it is obvious that for a call

auto s = f();

there is no way to deduce what type T is supposed to be.

As The Coronavirus Crisis Heats Up, Why Isn't America , Usually in health emergencies — HIV, vaping and more — the Centers for Disease Control and Prevention is key to shaping policy and  But that isn’t true for every interesting set of numbers. As an example, let’s look at the set of numbers of the form a + b √-5, or a +i b √5, where a and b are both integers and i is the

Why Isn't My Brain Working?: A Revolutionary Understanding of , Why Isn't My Brain Working?: A Revolutionary Understanding of Brain Decline and Effective Strategies to Recover Your Brain's Health: 8601420672192:  Why Your New Hard Drive Isn’t Showing Up in Windows (and How to Fix It) Jason Fitzpatrick @jasonfitzpatric Updated July 3, 2017, 4:24pm EDT.

Why Isn't My Brain Working?: A revolutionary , Amazon.com: Why Isn't My Brain Working?: A revolutionary understanding of brain decline and effective strategies to recover your brain's health eBook:  Outsourcing work to third-party vendors introduces risks that need to be managed. ISN provides contractor management software, ISNetworld, to help with the supplier management process including contractor safety and risk management.

Why isn't my app working?, Why isn't my app working? If you're having issues with your device or app, try these troubleshooting tricks: Try force-closing the app and reopening. Make sure​  Why isn't my Internet Explorer working? I have network and everything. It just turn it on so I have to you Firefox which perfectly works fine.

Comments
  • I feel that it is not in standard because code of this kind is easy to write, but very difficult to read and understand (what type is actually used). Standard writers include mostly features based on best practices, while your example seems to be as something which makes writing code harder.
  • but you can do that now almost - with lambdas.
  • @BhavinChirag I agree. Almost. Usingauto as return type isn't more explicit after all.
  • I think you found the best example to make it clear. Thank you very much. It was easy indeed, but I failed in finding the key point.
  • Technically speaking, the standard doesn't say that it's not allowed. It just doesn't say that it is. :-D