WEBVTT

00:00.280 --> 00:06.790
If a function calculates a value that can be calculated at compile time, you can mark it on the left

00:06.790 --> 00:08.890
of the declaration with the.

00:09.340 --> 00:14.530
For example, const expression here like this.

00:15.460 --> 00:23.020
Here with this the you're going to indicate that the compiler can optimize the code by computing the

00:23.020 --> 00:25.000
value at a compile time.

00:25.060 --> 00:30.180
So if the function value can be calculated at compile time, it means that the parameters in the function

00:30.230 --> 00:34.330
function call must be value can be calculated at compile time.

00:34.330 --> 00:42.100
So it means that the parameters, uh, in the function must be known at compile time and so they must

00:42.100 --> 00:42.970
be literal.

00:42.970 --> 00:45.190
So the function must also be single line.

00:45.190 --> 00:53.050
So if there is, if these restrictions are not met, then the compiler is free to ignore, uh, the

00:53.050 --> 00:53.920
specifier.

00:53.920 --> 01:00.130
But if you just compile it, the compiler won't say nothing here, but probably it will ignore the if

01:00.230 --> 01:03.920
these restrictions are not met.

01:04.280 --> 01:12.380
Uh, so the related in this inline specifier that, uh, this can be placed on the left of a function

01:12.380 --> 01:13.190
here.

01:13.870 --> 01:14.650
Inline.

01:15.760 --> 01:18.280
This can replaced the left of a function.

01:18.600 --> 01:24.470
Function declaration as a suggestion to the compiler that when other code call.

01:24.490 --> 01:30.730
Calls this function rather than rather than the compiler inserting a jump to the function in memory,

01:30.820 --> 01:36.290
the compiler should put a copy of the actual code in the calling function.

01:36.310 --> 01:43.840
Again, the compiler is free to ignore specifiers if this restrictions is not met.

01:44.800 --> 01:45.390
Here.

01:45.400 --> 01:48.880
So we're going to determine the return type here.

01:48.880 --> 01:54.720
So the functions may be written to run a routine and not a return value.

01:54.730 --> 02:02.740
So if this case this is the case, you must specify that the function returns the void here.

02:02.770 --> 02:03.580
Void here.

02:03.580 --> 02:08.380
But in this case, you're going to see error because we are returning something, right?

02:08.380 --> 02:11.170
So in most cases, a function will return a value.

02:11.170 --> 02:16.360
So if only indicate that the function has completed correctly.

02:16.360 --> 02:22.270
So there's no requirement that the calling function obtains the return value or does anything with it.

02:22.270 --> 02:27.610
So the calling function can simply ignore the return value.

02:27.610 --> 02:32.380
So there are two types, two ways to specify the return type.

02:32.680 --> 02:37.540
The first way is to give the type before the function name like this.

02:38.140 --> 02:44.930
In this case, this is an integer that returns integer, and this is the method used in most examples

02:44.930 --> 02:46.290
in this course so far.

02:46.310 --> 02:55.160
The second way is calling the trailing return type and requires that you place auto here auto as a return

02:55.160 --> 03:04.460
type before the function function name as and use the this syntax here like this.

03:05.940 --> 03:06.840
Integer.

03:06.870 --> 03:14.160
We use the syntax to give the actual return type after the parameter list.

03:14.160 --> 03:15.060
So.

03:16.030 --> 03:17.410
Uh, this function is so simple.

03:17.410 --> 03:20.440
That is a good candidate to be inlined.

03:20.440 --> 03:27.100
So the return type on the left is given auto here, meaning that the actual return type is specified

03:27.100 --> 03:31.120
after the parameter list and this operator.

03:31.120 --> 03:35.800
And it means that the return type is an integer.

03:35.800 --> 03:40.690
And this syntax has the same effect as using the integer on the left.

03:40.690 --> 03:41.230
So.

03:41.230 --> 03:42.110
But this is nice.

03:42.110 --> 03:47.710
This is useful when a function is templated and the return type may not be noticeable here.

03:47.710 --> 03:55.210
So in this trivial example, you can omit the return type entirely and just use the auto on the left

03:55.210 --> 03:56.560
of the function name.

03:56.560 --> 04:02.920
So this syntax means that the compiler will deduce the return type from the actual value returned.

04:02.920 --> 04:10.210
So clearly the compiler will know, will only know what return type is from the function body, so you

04:10.210 --> 04:14.350
can not provide a prototype for such functions.

04:14.350 --> 04:20.870
So finally, if a function does not return at all, for example, if it goes into a never ending loop

04:20.870 --> 04:23.600
to pull some value.

04:23.810 --> 04:33.740
So if it does not return a value at all, you can mark it with the C plus plus 11 attribute, the no

04:33.740 --> 04:44.000
return, no return attribute with this here so the compiler can use this attribute to read write more

04:44.000 --> 04:50.360
efficient code because it knows that the it does not need to provide the return value here.
