Boost.Contract

ML で Boost.Contract のレビューが開始されたというのを見て、自分もちょっと触ってみました。
Boost.Contract は契約プログラミングを行うためのライブラリみたいですね。

[ソース]

#include <contract.hpp>
#include <boost/detail/lightweight_test.hpp>


// int const
// postinc(int& value){
//     return value++;
// }

CONTRACT_FUNCTION(
    int const (postinc) ((int&) value)
        // precondition:    value < std::numeric_limits<int>::max()
        // postcondition:   value  == oldof value + 1
        //                  result == oldof valule
        precondition( value < std::numeric_limits<int>::max() )
        postcondition(
            auto result = return,
            auto old_value = CONTRACT_OLDOF value,
            value  == old_value + 1,
            result == old_value
        )
){
    return value++;
    // postcondition number 1 "value == old_value + 1" failed:
    // return value--;
}


int
main(){
    int value = 1;
    BOOST_TEST(postinc(value) == 1);
    BOOST_TEST(postinc(value) == 2);
    BOOST_TEST(value == 3);

    // precondition number 1 "value < std::numeric_limits<int>::max()"
//  value = std::numeric_limits<int>::max();
//  postinc(value);

    return 0;
}


どことなく Boost.Generic を思い出すようなコーディングスタイル。
なにこれこわい。
まぁシンタックスはアレな感じですが、読みやすいといえば読みやすいかしら。