logo
down
shadow

Template partial specialisation and dependent names


Template partial specialisation and dependent names

Content Index :

Template partial specialisation and dependent names
Tag : cpp , By : Kristian Hofslaeter
Date : November 29 2020, 01:01 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Template partial specialisation


Tag : cpp , By : eastcoastj
Date : March 29 2020, 07:55 AM
wish of those help Can somebody explain why are those two specializations indistinguishable to the compiler (gcc 4.5.1 @ ideone) , My understanding of the issue:
typedef S<S<a, b>, c, d> S2;

partial template specialisation on template class and member function


Tag : cpp , By : Alex Sadzawka
Date : March 29 2020, 07:55 AM
hope this fix your issue Short answer: You can't explicitly specialize a member template of an class template that is not explicitly specialized.
I guess using an overload as you suggested might be the simplest solution:
#include <list>
#include <string>

struct Filter
{
    // you constructor...
    template < typename... T > Filter(T...){}
};

template<typename T>
class SQLObject
{
     public:
        template<typename U>
        static std::list<T*> filter(const std::string& colum,
                                    const std::string& ope,const U& value);
        // v-here-v is the overload
        static std::list<T*> filter(const std::string& colum,
                                    const std::string& ope,
                                    const std::string& value);
        static std::list<T*> filter(const Filter& filter);
 };

// works
template<typename T>
std::list<T*> SQLObject<T>::filter(const std::string& colum,
                                   const std::string& ope,
                                   const std::string& value)
    {
    // no to_string need whith std::string
    return filter(Filter(colum,ope,value)); 
}

//[...]
std::string const& to_string(std::string const& p)  {  return p;  }

// class definition etc.

template<typename T>
template<typename U>
std::list<T*> SQLObject<T>::filter(const std::string& colum,
                                   const std::string& ope,const U& value)
{
    //use to_string with all others types
    using std::to_string;
    return filter(Filter(colum,ope,to_string(value))); 
}

Template partial specialisation not working with typedefs


Tag : cpp , By : nemof
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Inspired by this answer to a related question link, I tried the following and it seemed to work:
template<typename T>
struct HasRootType
{
private:
    typedef char no;
    struct yes { no m[2]; };

    static T* make();
    template<typename U>
    static yes check(U*, typename U::root_type* = 0);
    static no check(...);

public:
    static bool const value = sizeof(check(make())) == sizeof(yes);
};

template<typename T, bool = HasRootType<T>::value>
struct FindRootValueType
{
    typedef typename T::root_type type;
};

template<typename T>
struct FindRootValueType<T, false>
{
    typedef T type;
};

// define Base, A, B, C, etc here

Partial template member specialisation for arrays


Tag : cpp , By : Josh
Date : March 29 2020, 07:55 AM
it fixes the issue You can only specialize a single member function by providing all template arguments (you left the length as an argument), it would force you here to specify the array length.
So if you need a specialized version for arrays of strings, leaving the length as a parameter, you need a specialization of the class template for array of strings first.
template<class T>
class foo
{
    public:
    void tell() { cout << "general\n"; }
    void base() { cout << "ok"; }
};

template<class T, std::size_t N>
class foo<T[N]>
{
    public:
    void tell() { cout << "special arrays\n"; }
};

template<std::size_t N>
class foo<std::string[N]>
{
    public:
    void tell() { cout << "special string arrays\n"; }
};

template<>
void foo<std::string>::tell()
{
  cout << "string\n";   
}

int main()
{
  foo<std::string[2]> f;   
  f.tell();

  return 0;
}

Partial template specialisation without rewriting the class


Tag : cpp , By : Tom
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Since your matrix class is templated on the height and width, a square matrix is a matrix with those template parameters equal. You can have such a class as a parameter easily with the same N for the second and third template argument:
template <class T, int N>
auto get_det(const Matrix<T, N, N>& mat) -> float;
template <class T, int H, int W>
auto get_det(const Matrix<T, H, W>& mat) -> std::enable_if_t<H == W, float>;
template <class T, int H, int W>
struct Matrix {

  template <int N = H, int M = W>
  auto get_det() const -> std::enable_if_t<N == M, float> { return 2.4f; }
};
Matrix<int, 2, 3> not_square;
Matrix<int, 2, 2> square;

// error error: no matching member function for call to 'get_det'
// note: candidate template ignored: disabled by 'enable_if' [with N = 2, M = 3]
//not_square.get_det();

//OK:
square.get_det();
// No compilation error:
not_square.get_det<2,2>();
template <class T, int H, int W>
struct Matrix;

namespace detail {
template <class T, int N>
auto get_det(const Matrix<T, N, N>&) -> float { return 3.5; }
}

template <class T, int H, int W>
struct Matrix { 
  auto get_det2() const -> float { return detail::get_det(*this); }
};
Related Posts Related QUESTIONS :
  • Could someone explain this interesting behaviour with Sleep(1)?
  • Is it possible to roll a significantly faster version of modf
  • Updating pointer using signals and slots
  • How are classes more secure than structures?
  • finding "distance" between two pixel's colors
  • C++ Greatest Number Verification
  • Why does my token return NULL and how can I fix it?(c++)
  • C++ enforce conditions on inherited classes
  • what happened if an exception is not captured?
  • Redundant naming in C/C++ typedefs/structs
  • question about STL thread-safe and STL debugging
  • killing a separate thread having a socket
  • Returning the size of available virtual memory at run-time in C++
  • Parallel computing for integrals
  • How do I force my std::map to deallocate memory used?
  • C++ Templates: implicit conversion, no matching function for call to ctor
  • Adding python script to c++ project
  • C++ private pointer "leaking"?
  • Initializing Primitive Array to One Value
  • how is push_back implemented in STL vector?
  • C++ Profiling: KiFastSystemCallRet
  • Multiple rows with a single INSERT in SQLServer 2008
  • Use super class's address/pointer in initialization list
  • double fork using vfork
  • Convert char pointer (char*) to struct
  • Does anyone have good tips for using pc-lint?
  • C++ How fast is passing around objects?
  • template type's ctor arguments at instantiation time
  • Get list of windows in taskbar on Windows 7?
  • Curl connection options
  • Best cross-platform solution for network server?
  • simple c++ file opening issue
  • Switching from C++ (with a lot of STL use) to C for interpreter building
  • How can I access the JPEG image pixels as a 3D array like we do in MATLAB?
  • What wording in the C++ standard allows static_cast<non-void-type*>(malloc(N)); to work?
  • Avoid allocating in constructor or preserve simplicity (and RAII?)
  • Can C++ raise an error when std array initialization is too small?
  • Reference to end is ambiguous
  • Problem with basic usage of std::enable_if
  • How to print out a decimal number as octal number using setiosflags in C++
  • Open Visual Studio with solution and specific file and line
  • Enum value based on template type
  • Is there any way to swap nodes in std::list?
  • How to copy QString into wchar_t buffer
  • Make the compiler generate an empty default function for an std::function
  • Insert or push_back to end of a std::vector?
  • Best practice for const temporary types
  • Include CSV File in Complied Binary
  • Issue with binding non static function to callback
  • How can read from some files and write content of them with different form into files with same names
  • Why does auto deduce this variable as double and not float?
  • no instance of overloaded function "std::make_unique" matches the argument list, but works with unique_ptr con
  • How to see array size from a pointer in c++
  • Error taking address of temporary in Eclipse
  • Using an iterator to go through a vector and modify the contents
  • Are extern extern "C", and extern "C" extern, allowed?
  • Can't solve C2660 and C2065 Errors
  • C referencing C++ extern
  • How to write the definition of a derived class in c++?
  • Why when I include <cmath> I need to use the namespace std too?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com