/trunk/Examples/test-suite/li_std_list.i

# · Swig · 46 lines · 32 code · 14 blank · 0 comment · 0 complexity · 34a905ac3e9293ed42251961d43f9fd7 MD5 · raw file

  1. %module li_std_list
  2. %include "std_list.i"
  3. %{
  4. #include <algorithm>
  5. #include <functional>
  6. #include <numeric>
  7. %}
  8. namespace std {
  9. %template(IntList) list<int>;
  10. }
  11. %template(DoubleList) std::list<double>;
  12. %inline %{
  13. typedef float Real;
  14. %}
  15. namespace std {
  16. %template(RealList) list<Real>;
  17. }
  18. %inline %{
  19. double average(std::list<int> v) {
  20. return std::accumulate(v.begin(),v.end(),0.0)/v.size();
  21. }
  22. void halve_in_place(std::list<double>& v) {
  23. std::transform(v.begin(),v.end(),v.begin(),
  24. std::bind2nd(std::divides<double>(),2.0));
  25. }
  26. struct Struct {
  27. double num;
  28. Struct() : num(0.0) {}
  29. Struct(double d) : num(d) {}
  30. // bool operator==(const Struct &other) { return (num == other.num); }
  31. };
  32. %}