On May 11, 2010, at 7:26 PM, David Greene wrote:
> On Tuesday 11 May 2010 15:43:21 Chris Lattner wrote:
>> Hi All,
>>
>> LLVM now includes a C++ standard library, written by Howard Hinnant.
You
>> can read about it here:
>> http://blog.llvm.org/2010/05/new-libc-c-standard-library.html
>>
>> Or get the code here:
>> svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
>>
>> If you have questions or comments, please direct them to one of the
clang
>> mailing lists. Thanks!
>
> This looks cool, but I can't help wondering about the motivation.
libstdc++
> has a ton of useful functionality (debug mode, profile mode, etc.). Does
> libc++ plan to reproduce that?
debug mode yes. It isn't there yet. And I would like to limit it to being
ABI compatible with release mode. This will entail significant debug
functionality curtailment, but also eliminate numerous errors I've seen when
debug mode and release mode get accidentally mixed.
> What's driving libc++?
The possibility of being a superior solution.
----------------
// Container overhead example
#include <iostream>
#include <deque>
#include <map>
int main()
{
typedef std::map<int, int> M;
typedef std::deque<int> C;
std::cout << "sizeof map<int, int> = " <<
sizeof(M)/sizeof(void*) << '\n';
std::cout << "sizeof deque<int> = " <<
sizeof(C)/sizeof(void*) << '\n';
}
libc++:
sizeof map<int, int> = 3
sizeof deque<int> = 6
libstdc++:
sizeof map<int, int> = 6
sizeof deque<int> = 10
(smaller is better)
----------------
// Adding a few items to a sorted sequence and resorting
// (a real world use case)
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
int main()
{
typedef std::vector<int> V;
V v;
const int N = 100000000;
for (int i = 0; i < N; ++i)
v.push_back(i);
for (int i = N; i > 0;)
{
i -= N/10;
int j = v[i];
v.erase(v.begin() + i);
v.push_back(j);
}
std::random_shuffle(v.begin() + 9 * v.size() / 10, v.end());
// How long does it take to resort a vector when
// only the last 90% is unsorted?
std::time_t t0 = std::time(0);
std::sort(v.begin(), v.end());
std::time_t t1 = std::time(0);
std::cout << difftime(t1, t0) << " seconds\n";
}
libc++:
5 seconds
libstdc++:
22 seconds
(smaller is better)
----------------
This being said, clang will continue to be std::lib neutral. If libstdc++ meets
your needs better than libc++, then you should use it. libc++ will have to earn
its place.
-Howard