質問編集履歴

9

リンクを見やすくした。

2020/03/20 18:48

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -606,6 +606,8 @@
606
606
 
607
607
 
608
608
 
609
- 文字数上限に達してしまったので別の質問をたてて、続きを書きました
609
+ 文字数上限に達してしまったので別の質問をたてて、続きを書きまリンクはこちらです。
610
-
610
+
611
+
612
+
611
- https://teratail.com/questions/248408
613
+ * [C++ で多重ディスパッチをする方法と Julia 2](https://teratail.com/questions/248408)

8

追記3。

2020/03/20 18:48

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -595,3 +595,17 @@
595
595
 
596
596
 
597
597
  がどういう意味か分かりません。 `Animal ≠ Dog`, `Animal ≠ Cat` ではないということでしょうか?
598
+
599
+
600
+
601
+ ---
602
+
603
+
604
+
605
+ **追記3**:
606
+
607
+
608
+
609
+ 文字数上限に達してしまったので別の質問をたてて、続きを書きました。
610
+
611
+ https://teratail.com/questions/248408

7

追記2。

2020/03/20 18:46

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -594,4 +594,4 @@
594
594
 
595
595
 
596
596
 
597
- がどういう意味か分かりません。
597
+ がどういう意味か分かりません。 `Animal ≠ Dog`, `Animal ≠ Cat` ではないということでしょうか?

6

cat を追加。

2020/03/14 16:31

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -588,6 +588,8 @@
588
588
 
589
589
  Animal dog = Dog();
590
590
 
591
+ Animal cat = Cat();
592
+
591
593
  ```
592
594
 
593
595
 

5

日本語として修正。

2020/03/14 15:00

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -580,7 +580,7 @@
580
580
 
581
581
 
582
582
 
583
- どこが分かってないのか分かってきた気がします。Julia では `abstract type` はインスタンス化できないので、`Animal` 型のオブジェクトは存在しないので、私が Julia 脳になっているので C++ での
583
+ どこが分かってないのか分かってきた気がします。Julia では `abstract type` はインスタンス化できないので、`Animal` 型のオブジェクトは存在しません。私が Julia 脳になっているので C++ での
584
584
 
585
585
 
586
586
 

4

追記2。

2020/03/14 14:59

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -569,3 +569,27 @@
569
569
 
570
570
 
571
571
  にすべきでした。
572
+
573
+
574
+
575
+ ---
576
+
577
+
578
+
579
+ **追記2**:
580
+
581
+
582
+
583
+ どこが分かってないのか分かってきた気がします。Julia では `abstract type` はインスタンス化できないので、`Animal` 型のオブジェクトは存在しないので、私が Julia 脳になっているので C++ での
584
+
585
+
586
+
587
+ ```cpp
588
+
589
+ Animal dog = Dog();
590
+
591
+ ```
592
+
593
+
594
+
595
+ がどういう意味か分かりません。

3

追記1。

2020/03/14 14:58

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -507,3 +507,65 @@
507
507
 
508
508
 
509
509
  私の理解のうち何が間違っているのでしょうか?
510
+
511
+
512
+
513
+ ---
514
+
515
+
516
+
517
+ **追記1**:
518
+
519
+
520
+
521
+ ```julia
522
+
523
+ function content(::Box{<:Animal})
524
+
525
+ println("This box has an animal.")
526
+
527
+ end
528
+
529
+ ```
530
+
531
+
532
+
533
+ ```cpp
534
+
535
+ template <typename T>
536
+
537
+ auto content(Box<T> box) {
538
+
539
+ cout << "This box has an animal." << endl;
540
+
541
+ }
542
+
543
+ ```
544
+
545
+
546
+
547
+ の部分の Julia の `<:Animal` の部分が C++ だと表現できてないので C++20 の機能を使って
548
+
549
+
550
+
551
+ ```cpp
552
+
553
+ #include <concepts>
554
+
555
+
556
+
557
+ template <typename T>
558
+
559
+ requires std::derived_from<T, Animal>
560
+
561
+ auto content(Box<T> box) {
562
+
563
+ cout << "This box has an animal." << endl;
564
+
565
+ }
566
+
567
+ ```
568
+
569
+
570
+
571
+ にすべきでした。

2

再調整

2020/03/14 13:28

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -4,45 +4,9 @@
4
4
 
5
5
  >
6
6
 
7
- The choice of which method to execute when a function is applied is called *dispatch*. Julia allows
8
-
9
- the dispatch process to choose which of a function's methods to call based on the number of arguments
10
-
11
- given, and on the types of all of the function's arguments. This is different than traditional
12
-
13
- object-oriented languages, where dispatch occurs based only on the first argument, which often
14
-
15
- has a special argument syntax, and is sometimes implied rather than explicitly written as an argument.
16
-
17
- [1] Using all of a function's arguments to choose which method should be invoked, rather than
18
-
19
- just the first, is known as [multiple dispatch](https://en.wikipedia.org/wiki/Multiple_dispatch).
20
-
21
- Multiple dispatch is particularly useful for mathematical code, where it makes little sense to
22
-
23
- artificially deem the operations to "belong" to one argument more than any of the others: does
24
-
25
- the addition operation in `x + y` belong to `x` any more than it does to `y`? The implementation
26
-
27
- of a mathematical operator generally depends on the types of all of its arguments. Even beyond
28
-
29
- mathematical operations, however, multiple dispatch ends up being a powerful and convenient paradigm
30
-
31
- for structuring and organizing programs.
32
-
33
- >>
34
-
35
- [1]:
36
-
37
- In C++ or Java, for example, in a method call like `obj.meth(arg1,arg2)`, the object obj "receives"
38
-
39
- the method call and is implicitly passed to the method via the `this` keyword, rather than as
40
-
41
- an explicit method argument. When the current `this` object is the receiver of a method call,
42
-
43
- it can be omitted altogether, writing just `meth(arg1,arg2)`, with `this` implied as the receiving
44
-
45
- object.
7
+ The choice of which method to execute when a function is applied is called *dispatch*. Julia allows the dispatch process to choose which of a function's methods to call based on the number of arguments given, and on the types of all of the function's arguments. This is different than traditional object-oriented languages, where dispatch occurs based only on the first argument, which often has a special argument syntax, and is sometimes implied rather than explicitly written as an argument. [1] Using all of a function's arguments to choose which method should be invoked, rather than just the first, is known as [multiple dispatch](https://en.wikipedia.org/wiki/Multiple_dispatch). Multiple dispatch is particularly useful for mathematical code, where it makes little sense to artificially deem the operations to "belong" to one argument more than any of the others: does the addition operation in `x + y` belong to `x` any more than it does to `y`? The implementation of a mathematical operator generally depends on the types of all of its arguments. Even beyond mathematical operations, however, multiple dispatch ends up being a powerful and convenient paradigm for structuring and organizing programs.
8
+
9
+ >> [1]: In C++ or Java, for example, in a method call like `obj.meth(arg1,arg2)`, the object obj "receives" the method call and is implicitly passed to the method via the `this` keyword, rather than as an explicit method argument. When the current `this` object is the receiver of a method call, it can be omitted altogether, writing just `meth(arg1,arg2)`, with `this` implied as the receiving object.
46
10
 
47
11
 
48
12
 

1

引用部分を見やすく変更した。

2020/03/14 07:25

投稿

Paalon
Paalon

スコア232

test CHANGED
File without changes
test CHANGED
@@ -4,13 +4,45 @@
4
4
 
5
5
  >
6
6
 
7
- The choice of which method to execute when a function is applied is called dispatch. Julia allows the dispatch process to choose which of a function's methods to call based on the number of arguments given, and on the types of all of the function's arguments. This is different than traditional object-oriented languages, where dispatch occurs based only on the first argument, which often has a special argument syntax, and is sometimes implied rather than explicitly written as an argument. [1] Using all of a function's arguments to choose which method should be invoked, rather than just the first, is known as multiple dispatch. Multiple dispatch is particularly useful for mathematical code, where it makes little sense to artificially deem the operations to "belong" to one argument more than any of the others: does the addition operation in x + y belong to x any more than it does to y? The implementation of a mathematical operator generally depends on the types of all of its arguments. Even beyond mathematical operations, however, multiple dispatch ends up being a powerful and convenient paradigm for structuring and organizing programs.
7
+ The choice of which method to execute when a function is applied is called *dispatch*. Julia allows
8
+
9
+ the dispatch process to choose which of a function's methods to call based on the number of arguments
10
+
11
+ given, and on the types of all of the function's arguments. This is different than traditional
12
+
13
+ object-oriented languages, where dispatch occurs based only on the first argument, which often
14
+
15
+ has a special argument syntax, and is sometimes implied rather than explicitly written as an argument.
16
+
17
+ [1] Using all of a function's arguments to choose which method should be invoked, rather than
18
+
19
+ just the first, is known as [multiple dispatch](https://en.wikipedia.org/wiki/Multiple_dispatch).
20
+
21
+ Multiple dispatch is particularly useful for mathematical code, where it makes little sense to
22
+
23
+ artificially deem the operations to "belong" to one argument more than any of the others: does
24
+
25
+ the addition operation in `x + y` belong to `x` any more than it does to `y`? The implementation
26
+
27
+ of a mathematical operator generally depends on the types of all of its arguments. Even beyond
28
+
29
+ mathematical operations, however, multiple dispatch ends up being a powerful and convenient paradigm
30
+
31
+ for structuring and organizing programs.
8
32
 
9
33
  >>
10
34
 
11
- [1]
12
-
13
- In C++ or Java, for example, in a method call like obj.meth(arg1,arg2), the object obj "receives" the method call and is implicitly passed to the method via the this keyword, rather than as an explicit method argument. When the current this object is the receiver of a method call, it can be omitted altogether, writing just meth(arg1,arg2), with this implied as the receiving object.
35
+ [1]:
36
+
37
+ In C++ or Java, for example, in a method call like `obj.meth(arg1,arg2)`, the object obj "receives"
38
+
39
+ the method call and is implicitly passed to the method via the `this` keyword, rather than as
40
+
41
+ an explicit method argument. When the current `this` object is the receiver of a method call,
42
+
43
+ it can be omitted altogether, writing just `meth(arg1,arg2)`, with `this` implied as the receiving
44
+
45
+ object.
14
46
 
15
47
 
16
48