English 中文(简体)
C++ 模板专业化的附带问题
原标题:C++ traits question for template specialization
  • 时间:2023-05-23 02:53:05
  •  标签:
  • c++

我有两个班子:

class RowMatrix
{
public:
    double* getRowSlice ();
    double get (int row, int column);
    void set (int row, int column);
};

class ColumnMatrix
{
public:
    double* getColumnSlice ();
    double get (int row, int column);
    void set (int row, int column);
};

现在,在病媒操作方面,获得/获得机会(RowSlice)比使用更通用的获取/固定操作更快。

template<class MatrixOut, class MatrixIn>
copy (MatrixOut& out, const MatrixIn& in)
{
  if (in.isRowMatrix () && out.isRowMatrix ())
  {
    // row based copy
    int rows = in.getNumRows ();
    for (int y = 0; y < rows; ++y)
    {
       vectorCopy (out.getRowSlice (y), in.getRowSlice (y));
    }
  }
  else if (in.isRowMatrix () && out.isRowMatrix ())
  {
    // column based copy
  }
  else
  {
    genericCopy (out, in);
  }
}

目前的问题是,汇编者将产生错误,使RowSlice在ColumnMatrix失踪,在RawMatrix失踪。

如何专门实施? 这里的一个主要问题是,由于我有几个不同的罗·马塔基斯和哥伦·马西基斯执行工作(它们相互继承)。 因此,制作复制件和提件的比照;RowMatrix1, RowMatrix1>对于Mat Rowrix 执行和复制复制的不同组合而言;ColumnMatrix1, Columnrix2> 执行。 我不想为这些阶层创造遗产。 这也是我希望优化的算法之一。

我认为,使用C++海峡会有所助益,但我仍然有同样的错误。

template<bool a, bool b>
class MatrixTraits
{
  static bool isRowMatrix () { return a; }
  static bool isColumnMatrix () { return b; }
};

class RowMatrix
{
public:
    typedef MatrixTraits<true, false>  Traits;
...
};

class ColumnMatrix
{
public:
    typedef MatrixTraits<false, true>  Traits;
...
};

template<class MatrixOut, class MatrixIn>
copy (MatrixOut& out, const MatrixIn& in)
{
  if (MatrixIn::Traits::isRowMatrix () && MatrixOut::Traits::isRowMatrix ())
  {
    // row based copy
    ...
  }
  else if (MatrixIn::Traits::isColumnMatrix () && MatrixOut::Traits::isColumnMatrix ())
  {
    // column based copy
  }
  else
  {
    genericCopy (out, in);
  }
}

我仍然发现,Matrix一栏缺失。

谁能帮助? 感谢。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签