consolidate all repos to one for archive
This commit is contained in:
32
semester_2/programiranje_2/primeri/Example20/C.h
Normal file
32
semester_2/programiranje_2/primeri/Example20/C.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef EXAMPLE20_C_H
|
||||
#define EXAMPLE20_C_H
|
||||
|
||||
#include <cstring>
|
||||
|
||||
// primary template
|
||||
template < typename T >
|
||||
class C {
|
||||
public:
|
||||
bool less (const T& v1, const T& v2) {
|
||||
return v1<v2;
|
||||
}
|
||||
};
|
||||
|
||||
// explicit template specialization
|
||||
template<>
|
||||
class C<const char*> {
|
||||
public:
|
||||
bool less (const char* v1, const char* v2) {
|
||||
return strcmp(v1,v2)<0;
|
||||
}
|
||||
};
|
||||
|
||||
// partial specialization
|
||||
template< typename T >
|
||||
class C<T*> {
|
||||
public:
|
||||
bool less (T* v1, T* v2) {
|
||||
return *v1 < *v2; }
|
||||
};
|
||||
|
||||
#endif //EXAMPLE20_C_H
|
19
semester_2/programiranje_2/primeri/Example20/main.cpp
Normal file
19
semester_2/programiranje_2/primeri/Example20/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <iostream>
|
||||
#include "C.h"
|
||||
|
||||
int main() {
|
||||
int i1 = 1;
|
||||
int i2 = 2;
|
||||
C<int> o1;
|
||||
C<double> o2;
|
||||
C<const char*> o3;
|
||||
C<int*> o4;
|
||||
std::cout << o1.less(i1, i2) << " ";
|
||||
std::cout << o2.less(1.2, 3.4) << " ";
|
||||
std::cout << o3.less("abcd", "abcx") << " ";
|
||||
std::cout << o4.less(&i1, &i2) << std::endl;
|
||||
//o2=o1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user