소스 검색

string magic

Former-commit-id: 75006a1b4f1b57389512d91a386019e05e07640c
Alec Jacobson (jalec 12 년 전
부모
커밋
6548d97306
2개의 변경된 파일22개의 추가작업 그리고 0개의 파일을 삭제
  1. 11 0
      include/igl/C_STR.h
  2. 11 0
      include/igl/STR.h

+ 11 - 0
include/igl/C_STR.h

@@ -0,0 +1,11 @@
+#ifndef C_STR_H
+#define C_STR_H
+// http://stackoverflow.com/a/2433143/148668
+// Suppose you have a function:
+//   void func(const char * c);
+// Then you can write:
+//   func(C_STR("foo"<<1<<"bar"));
+#include <string>
+#include <sstream>
+#define C_STR(X) static_cast<std::ostringstream&>(std::ostringstream().seekp(0) << X).str().c_str()
+#endif

+ 11 - 0
include/igl/STR.h

@@ -0,0 +1,11 @@
+#ifndef STR_H
+#define STR_H
+// http://stackoverflow.com/a/2433143/148668
+#include <string>
+#include <sstream>
+// Suppose you have a function:
+//   void func(std::string c);
+// Then you can write:
+//   func(STR("foo"<<1<<"bar"));
+#define STR(X) static_cast<std::ostringstream&>(std::ostringstream().seekp(0) << X).str()
+#endif