2012-07-17 7 views
5

単純なタイプミスがあるかどうかはわかりませんが、タプルの両端キューを並べ替える際に問題が発生しています。ブーストタプルの両端キューを並べ替える

だから、私の両端キューは次のようになります。

std::deque<boost::tuple<unsigned int, unsigned int> > messages; 

そして私は、ソートする私のコールを持っている:

sort(messages.begin(), messages.end(), msg_sort_criteria); 

そして、私のソート機能:

bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs, boost::tuple<unsigned int, unsigned int> rhs) 
{ 
    return boost::get<1>(lhs) < boost::get<1>(rhs); 
} 

される何が起こりますstl_heap.hとstl_algo.hでエラーが出ることがあります。例えば 、

というオブジェクトタイプ「<bound member function type>」は関数または 関数のパラメータではありません。


編集:明確にするため

、これはすべてのクラスのprivateメンバー内で行われます。

class Messages::MessageImpl{ 
private: 
    std::deque<boost::tuple<unsigned int, unsigned int> > messages; 

    bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs, boost::tuple<unsigned int, unsigned int> rhs) 
    { 
    return boost::get<1>(lhs) < boost::get<1>(rhs); 
    } 

    void fn() 
    { 
    sort(msg_queue_.begin(), msg_queue_.end(), msg_sort_criteria); 
    } 
} 
+1

'free関数やメンバ関数をmsg_sort_criteria'ていますか?前者の場合は、より多くのコードを表示する必要があります。 ()、messages.end()、&myClassName :: msg_sort_criteria()をソートするには、 ''ソート(messages.begin()、msg_sort_criteria) ); '。 – ildjarn

+0

このコードはすべて、クラスのプライベートメンバー内で行われています。私はそれに応じて更新します – espais

+0

'tuple'の最初のメンバで意図的にソートしていますか?最初の要素が等しいアイテムの順序を気にしない場合は、デフォルトのタプル 'operator <'を使うだけで、ソート述語はまったく気にしません。 –

答えて

1

コメントからほとんど再投稿。

はにあなたの実装を変更し

class Messages::MessageImpl{ 
private: 
    std::deque<boost::tuple<unsigned int, unsigned int> > messages; 

    static bool msg_sort_criteria(boost::tuple<unsigned int, unsigned int> lhs, 
           boost::tuple<unsigned int, unsigned int> rhs) 
    { 
    return boost::get<1>(lhs) < boost::get<1>(rhs); 
    } 

    void fn() 
    { 
    sort(msg_queue_.begin(), msg_queue_.end(), &MessageImpl::msg_sort_criteria); 
    } 
}; 
+0

サー、ありがとうのように働いてくれてありがとう – espais

関連する問題