title: Trouble using import in C++20
body: <p>Now that most of the compilers have adequate support for C++20. This code below, which uses the import module should compile without errors and warnings. But when I compile the code using g++ I get the following error <a href="https://i.stack.imgur.com/PLrce.png" rel="nofollow noreferrer">Code Compilation Screenshot</a></p>
  <p>I've read <a href="https://docs.microsoft.com/en-us/cpp/cpp/modules-cpp?view=msvc-160" rel="nofollow noreferrer">Overview of Modules</a> but having hard time to understand given that I'm fairly a beginner in programming. Is there anything wrong that I'm doing or missing that the code won't run?</p>
  <pre><code>#include &lt;cerrno&gt;
  #include &lt;cstdlib&gt;
  import &lt;algorithm&gt;;
  import &lt;fstream&gt;;
  import &lt;initializer_list&gt;;
  import &lt;iostream&gt;;
  import &lt;iterator&gt;;
  import &lt;locale&gt;;
  import &lt;string&gt;;
  import &lt;system_error&gt;;
  import &lt;vector&gt;;
  
  template&lt;class C&gt;
  struct text : std::basic_string&lt;C&gt;
  {
    using super = std::basic_string&lt;C&gt;;
    constexpr text() noexcept : super{} {}
    text(text&amp;&amp;) = default;
    text(text const&amp;) = default;
    text&amp; operator=(text const&amp;) = default;
    text&amp; operator=(text&amp;&amp;) = default;
    constexpr explicit operator bool() const noexcept {
      return not this-&gt;empty();
    }
  };
  
  /// Read lines of text from @p in to @p iter. Lines are appended to @p iter.
  /// @param in the input stream
  /// @param iter an output iterator
  template&lt;class Ch&gt;
  auto read(std::basic_istream&lt;Ch&gt;&amp; in) -&gt; std::vector&lt;text&lt;Ch&gt;&gt;
  {
      std::vector&lt;text&lt;Ch&gt;&gt; result;
      
      text&lt;Ch&gt; line;
      while (std::getline(in, line))
          result.emplace_back(std::move(line));
  
      return result;
  }
  
  /// Main program.
  int main(int argc, char* argv[])
  try
  {
      // Throw an exception if an unrecoverable input error occurs, e.g.,
      // disk failure.
      std::cin.exceptions(std::ios_base::badbit);
  
      // Part 1. Read the entire input into text. If the command line names a file,
      // read that file. Otherwise, read the standard input.
      std::vector&lt;text&lt;char&gt;&gt; text; ///&lt; Store the lines of text here
      if (argc &lt; 2)
          text = read(std::cin);
      else
      {
          std::ifstream in{argv[1]};
          if (not in)
          {
              std::cout &lt;&lt; argv[1] &lt;&lt; &quot;: &quot; &lt;&lt; std::system_category().message(errno) &lt;&lt; '\n';
              return EXIT_FAILURE;
          }
          text = read(in);
      }
  
      // Part 2. Sort the text. The second command line argument, if present,
      // names a locale, to control the sort order. Without a command line
      // argument, use the default locale (which is obtained from the OS).
      std::locale const&amp; loc{ std::locale(argc &gt;= 3 ? argv[2] : &quot;&quot;) };
      std::collate&lt;char&gt; const&amp; collate{ std::use_facet&lt;std::collate&lt;char&gt;&gt;(loc) };
      std::ranges::sort(text,
          [&amp;collate](auto const&amp; a, auto const&amp; b)
          {
              return collate.compare(to_address(cbegin(a)), to_address(cend(a)),
                  to_address(cbegin(b)), to_address(cend(b))) &lt; 0;
          }
      );
   
      // Part 3. Print the sorted text.
     for (auto const&amp; line :  text)
        std::cout &lt;&lt; line &lt;&lt; '\n';
  }
  catch (std::exception&amp; ex)
  {
      std::cerr &lt;&lt; &quot;Caught exception: &quot; &lt;&lt; ex.what() &lt;&lt; '\n';
      std::cerr &lt;&lt; &quot;Terminating program.\n&quot;;
      std::exit(EXIT_FAILURE);
  }
  catch (...)
  {
      std::cerr &lt;&lt; &quot;Caught unknown exception type.\nTerminating program.\n&quot;;
      std::exit(EXIT_FAILURE);
  }
  </code></pre>
  <p>(The code is taken from the website of the book <code>Exploring C++20 by Ray Lischner</code> <a href="https://cpphelp.com/exploring/exploring-20/" rel="nofollow noreferrer">Website</a>)</p>