#generic_programming — Public Fediverse posts
Live and recent posts from across the Fediverse tagged #generic_programming, aggregated by home.social.
-
3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup
https://www.stroustrup.com/programming.html
#ycombinator #Programming_Principles_and_Practice_Using_C #Bjarne_Stroustrup #C #text_book #object_oriented_programming #design #generic_programming #programming -
3rd Edition of Programming: Principles and Practice Using C++ by Stroustrup
https://www.stroustrup.com/programming.html
#ycombinator #Programming_Principles_and_Practice_Using_C #Bjarne_Stroustrup #C #text_book #object_oriented_programming #design #generic_programming #programming -
Considering a generic function, that accepts a count of numbers (usual + - * / algebra) and returns their average (sum over count), what requirements make sense to be imposed on the number to allow division by count?
(count is 2 in example pseudo code)
1. explicit construction from a single natural number:
(n1 + n2)/number(2)2. straight up a division operator that accepts a natural number as second argument:
(n1 + n2)/23. multiplication identity constructor/value that can be accumulated (using addition) to reach count:
(n1 + n2)/(number::one + number::one)4. addition operator that accepts a natural number as second argument (assuming zero/default constructor available):
(n1 + n2)/(number() + 2)