2

Is there a way, that the following function is only visible, if a certain pre-set type is used?

//used, when T == double || T == float
template<typename T, size_t M, size_t K, size_t N>
void foo2d(){}
//used, when T == int || T == uint64
template<typename T, size_t M, size_t K, size_t N>
void foo3d(){}

how would i write them, and how would i call them?

This is not a duplicate, the other question does not answer this one, and even if, i cant even grasp the concept, how am i supposed to understand the other answers ... but thanks for the quick marking

Clebo Sevic
  • 581
  • 1
  • 7
  • 17
  • well then tell me which answer is the right one – Clebo Sevic Mar 12 '19 at 17:11
  • 1
    as if i could see this, if i ask a qeustion this basic – Clebo Sevic Mar 12 '19 at 17:11
  • 2
    You can use `enable_if` and SFINAE on the return value to do this, for example: `template std::enable_if_t< std::is_floating_point_v, T > foo2d() {}`. This is only callable for `float`, `double`, and `long double`. – metal Mar 12 '19 at 17:23
  • 1
    I agree it's not quite close enough to close as a dupe. – metal Mar 12 '19 at 17:24
  • @metal Thank you, what would the equivalent be for int and uint64_t (basically whole numbers)? – Clebo Sevic Mar 12 '19 at 17:25
  • @metal well, the duplicate basically came in as soon as i asked this question, and it is not like i didnt lokk at other questions beforehand – Clebo Sevic Mar 12 '19 at 17:26
  • 1
    [`std::is_integral_v`](https://en.cppreference.com/w/cpp/types/is_integral), which includes some things you may not expect like `char` and `bool`. Otherwise, you can build your own with `std::is_same_v` and other things in ``. – metal Mar 12 '19 at 17:26
  • @metal could you maybe write it as an answer, with proper code indentation, i am still struggling a bit with this kind of code – Clebo Sevic Mar 12 '19 at 17:35
  • 1
    Perhaps you ask a new question with your specific problems demonstrated. That way I can reply in an answer box with formatting. I cannot do so here because the question is closed. (Note that someone has added more dupe questions that are closer matches.) – metal Mar 12 '19 at 19:55
  • Thank you for the offer, i actually did, and already got the answer, i'll link it here, so you can see what the problem was: https://stackoverflow.com/questions/55128521/what-are-the-syntax-and-semantics-of-c-templated-code – Clebo Sevic Mar 12 '19 at 19:59

0 Answers0