0

For last couple of days I have been experimenting the behavior of few of the functions of filesystem and experimental/filesystem library.

Note: I ran the code on https://godbolt.org/

below is the code snippet with its output

1. experimental/filesystem

#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;

int main()
{
auto  p = fs::path("//net");
std::cout<<"p = " << p
         <<"\np.root_name= "<< p.root_name()
         <<"\nand p.root_Dir= "<< p.root_directory()
         <<"\np.is_absolute= "<<p.is_absolute()<<std::endl;
}

output:

p = "//net"    
p.root_name= "//net"    
and p.root_Dir= ""    
p.is_absolute= 0

enter image description here 2. filesystem

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem;
 
int main()
{
auto  p = fs::path("//net");
std::cout<<"p = " << p
         <<"\np.root_name= "<< p.root_name()
         <<"\nand p.root_Dir= "<< p.root_directory()
         <<"\np.is_absolute= "<<p.is_absolute()<<std::endl;
}

output:

p = "//net"
p.root_name= ""
and p.root_Dir= "/"
p.is_absolute= 1

Is there any way to look into the implementation of these functions ?

enter image description here

Praveer Kumar
  • 912
  • 1
  • 12
  • 25
  • 1
    warning: std::experimental::filesystem has now been deprecated in favor of C++17's std::filesystem. Please stop using it and start using std::filesystem. This experimental version will be removed in LLVM 11. – brc-dd Jul 09 '20 at 13:33
  • Search for the source code of the lib and look it up there. – just a guy Jul 09 '20 at 13:34
  • 1
    Yes, I know it will be deprecated . But I want to know why the behaviour is different? – Praveer Kumar Jul 09 '20 at 13:35
  • 2
    Because they were experimenting? What's the point in worrying about it. – Asteroids With Wings Jul 09 '20 at 13:39
  • if experimental was supposed to be exactly like the final, it wouldn't need to exist. Don't be surprised if something called "experimental" is in an experimental state – 463035818_is_not_an_ai Jul 09 '20 at 13:47
  • Then which one is the correct behaviour? – Praveer Kumar Jul 09 '20 at 13:48
  • 1
    @PraveerKumar the one which you are getting in the second one... On the latest experimental version of LLVM, I am [not even able to reproduce](https://wandbox.org/permlink/UcrvtzAnE9xa5N0t) the first output! They have made a revision somewhere in between previous release and the upcoming one... – brc-dd Jul 09 '20 at 13:50

0 Answers0