1
00:00:00,280 --> 00:00:06,790
If a function calculates a value that can be calculated at compile time, you can mark it on the left

2
00:00:06,790 --> 00:00:08,890
of the declaration with the.

3
00:00:09,340 --> 00:00:14,530
For example, const expression here like this.

4
00:00:15,460 --> 00:00:23,020
Here with this the you're going to indicate that the compiler can optimize the code by computing the

5
00:00:23,020 --> 00:00:25,000
value at a compile time.

6
00:00:25,060 --> 00:00:30,180
So if the function value can be calculated at compile time, it means that the parameters in the function

7
00:00:30,230 --> 00:00:34,330
function call must be value can be calculated at compile time.

8
00:00:34,330 --> 00:00:42,100
So it means that the parameters, uh, in the function must be known at compile time and so they must

9
00:00:42,100 --> 00:00:42,970
be literal.

10
00:00:42,970 --> 00:00:45,190
So the function must also be single line.

11
00:00:45,190 --> 00:00:53,050
So if there is, if these restrictions are not met, then the compiler is free to ignore, uh, the

12
00:00:53,050 --> 00:00:53,920
specifier.

13
00:00:53,920 --> 00:01:00,130
But if you just compile it, the compiler won't say nothing here, but probably it will ignore the if

14
00:01:00,230 --> 00:01:03,920
these restrictions are not met.

15
00:01:04,280 --> 00:01:12,380
Uh, so the related in this inline specifier that, uh, this can be placed on the left of a function

16
00:01:12,380 --> 00:01:13,190
here.

17
00:01:13,870 --> 00:01:14,650
Inline.

18
00:01:15,760 --> 00:01:18,280
This can replaced the left of a function.

19
00:01:18,600 --> 00:01:24,470
Function declaration as a suggestion to the compiler that when other code call.

20
00:01:24,490 --> 00:01:30,730
Calls this function rather than rather than the compiler inserting a jump to the function in memory,

21
00:01:30,820 --> 00:01:36,290
the compiler should put a copy of the actual code in the calling function.

22
00:01:36,310 --> 00:01:43,840
Again, the compiler is free to ignore specifiers if this restrictions is not met.

23
00:01:44,800 --> 00:01:45,390
Here.

24
00:01:45,400 --> 00:01:48,880
So we're going to determine the return type here.

25
00:01:48,880 --> 00:01:54,720
So the functions may be written to run a routine and not a return value.

26
00:01:54,730 --> 00:02:02,740
So if this case this is the case, you must specify that the function returns the void here.

27
00:02:02,770 --> 00:02:03,580
Void here.

28
00:02:03,580 --> 00:02:08,380
But in this case, you're going to see error because we are returning something, right?

29
00:02:08,380 --> 00:02:11,170
So in most cases, a function will return a value.

30
00:02:11,170 --> 00:02:16,360
So if only indicate that the function has completed correctly.

31
00:02:16,360 --> 00:02:22,270
So there's no requirement that the calling function obtains the return value or does anything with it.

32
00:02:22,270 --> 00:02:27,610
So the calling function can simply ignore the return value.

33
00:02:27,610 --> 00:02:32,380
So there are two types, two ways to specify the return type.

34
00:02:32,680 --> 00:02:37,540
The first way is to give the type before the function name like this.

35
00:02:38,140 --> 00:02:44,930
In this case, this is an integer that returns integer, and this is the method used in most examples

36
00:02:44,930 --> 00:02:46,290
in this course so far.

37
00:02:46,310 --> 00:02:55,160
The second way is calling the trailing return type and requires that you place auto here auto as a return

38
00:02:55,160 --> 00:03:04,460
type before the function function name as and use the this syntax here like this.

39
00:03:05,940 --> 00:03:06,840
Integer.

40
00:03:06,870 --> 00:03:14,160
We use the syntax to give the actual return type after the parameter list.

41
00:03:14,160 --> 00:03:15,060
So.

42
00:03:16,030 --> 00:03:17,410
Uh, this function is so simple.

43
00:03:17,410 --> 00:03:20,440
That is a good candidate to be inlined.

44
00:03:20,440 --> 00:03:27,100
So the return type on the left is given auto here, meaning that the actual return type is specified

45
00:03:27,100 --> 00:03:31,120
after the parameter list and this operator.

46
00:03:31,120 --> 00:03:35,800
And it means that the return type is an integer.

47
00:03:35,800 --> 00:03:40,690
And this syntax has the same effect as using the integer on the left.

48
00:03:40,690 --> 00:03:41,230
So.

49
00:03:41,230 --> 00:03:42,110
But this is nice.

50
00:03:42,110 --> 00:03:47,710
This is useful when a function is templated and the return type may not be noticeable here.

51
00:03:47,710 --> 00:03:55,210
So in this trivial example, you can omit the return type entirely and just use the auto on the left

52
00:03:55,210 --> 00:03:56,560
of the function name.

53
00:03:56,560 --> 00:04:02,920
So this syntax means that the compiler will deduce the return type from the actual value returned.

54
00:04:02,920 --> 00:04:10,210
So clearly the compiler will know, will only know what return type is from the function body, so you

55
00:04:10,210 --> 00:04:14,350
can not provide a prototype for such functions.

56
00:04:14,350 --> 00:04:20,870
So finally, if a function does not return at all, for example, if it goes into a never ending loop

57
00:04:20,870 --> 00:04:23,600
to pull some value.

58
00:04:23,810 --> 00: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

59
00:04:33,740 --> 00:04:44,000
return, no return attribute with this here so the compiler can use this attribute to read write more

60
00:04:44,000 --> 00:04:50,360
efficient code because it knows that the it does not need to provide the return value here.
